Skip to content

Commit 21d3505

Browse files
author
Cruz Monrreal
authored
Merge pull request #5 from yennster/master
Add "Application Flow Control" examples and READMEs
2 parents d66166f + ffc528f commit 21d3505

File tree

18 files changed

+119
-0
lines changed

18 files changed

+119
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
BUILD/
3+
.mbed
4+
projectfiles
5+
*.py*
6+
mbed-os/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Application Flow Control: Busy wait button example
2+
3+
A digital input monitoring implementation with busy wait.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "mbed.h"
2+
3+
DigitalIn button(SW1); // Change to match your board
4+
DigitalOut led(LED1);
5+
6+
#define BUTTON_PRESS 0
7+
8+
int main() {
9+
while(1) {
10+
if(BUTTON_PRESS == button){
11+
led = !led;
12+
wait(1);
13+
}
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7

Flow-Control/Busy-Wait/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Application Flow Control: Busy wait example
2+
3+
A busy wait Blinky implementation.

Flow-Control/Busy-Wait/main.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "mbed.h"
2+
3+
DigitalOut myled(LED1);
4+
5+
int main() {
6+
while(1) {
7+
myled = 1;
8+
// printf("LED On\r\n");
9+
wait(0.2);
10+
myled = 0;
11+
// printf("LED Off \r\n");
12+
wait(0.2);
13+
}
14+
}

Flow-Control/Busy-Wait/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Application Flow Control: Interrupt button example
2+
3+
A digital input monitoring implementation with an interrupt.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "mbed.h"
2+
3+
InterruptIn button(SW1);
4+
DigitalOut led(LED1);
5+
DigitalOut heartbeat(LED2);
6+
7+
void toggle() {
8+
led = !led;
9+
}
10+
11+
int main() {
12+
button.rise(&toggle); // call toggle function on the rising edge
13+
while(1) { // wait around, interrupts will interrupt this!
14+
heartbeat = !heartbeat;
15+
wait(0.25);
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7

Flow-Control/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Application Flow Control
2+
3+
The examples in this folder utilize Blinky in order to explore flow control and task management in Arm Mbed OS applications.

Flow-Control/Thread/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Application Flow Control: Thread example
2+
3+
A threaded Blinky implementation.

Flow-Control/Thread/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "mbed.h"
2+
3+
DigitalOut led1(LED1);
4+
DigitalOut led2(LED2);
5+
Thread thread;
6+
7+
void led2_thread() {
8+
while (true) {
9+
led2 = !led2;
10+
wait(1);
11+
}
12+
}
13+
14+
int main() {
15+
// Create a thread to execute the function led2_thread
16+
thread.start(led2_thread);
17+
// led2_thread is executing concurrently with main at this point
18+
19+
while (true) {
20+
led1 = !led1;
21+
wait(0.5);
22+
}
23+
}

Flow-Control/Thread/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7

Flow-Control/Ticker/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Application Flow Control: Ticker example
2+
3+
A ticker Blinky implementation.

Flow-Control/Ticker/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "mbed.h"
2+
3+
Ticker flipper;
4+
DigitalOut led1(LED1);
5+
DigitalOut led2(LED2);
6+
7+
void flip() {
8+
led2 = !led2;
9+
}
10+
11+
int main() {
12+
led2 = 1;
13+
flipper.attach(&flip, 2.0); // call flip function every 2 seconds
14+
15+
// spin in a main loop. flipper will interrupt it to call flip
16+
while(1) {
17+
led1 = !led1;
18+
wait(0.2);
19+
}
20+
}

Flow-Control/Ticker/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7

IdleLoop/mbed-os.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7

0 commit comments

Comments
 (0)