Skip to content

Add "Application Flow Control" examples and READMEs #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
BUILD/
.mbed
projectfiles
*.py*
mbed-os/
3 changes: 3 additions & 0 deletions Flow-Control/Busy-Wait-Button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Flow Control: Busy wait button example

A digital input monitoring implementation with busy wait.
15 changes: 15 additions & 0 deletions Flow-Control/Busy-Wait-Button/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "mbed.h"

DigitalIn button(SW1); // Change to match your board
DigitalOut led(LED1);

#define BUTTON_PRESS 0

int main() {
while(1) {
if(BUTTON_PRESS == button){
led = !led;
wait(1);
}
}
}
1 change: 1 addition & 0 deletions Flow-Control/Busy-Wait-Button/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7
3 changes: 3 additions & 0 deletions Flow-Control/Busy-Wait/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Flow Control: Busy wait example

A busy wait Blinky implementation.
14 changes: 14 additions & 0 deletions Flow-Control/Busy-Wait/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "mbed.h"

DigitalOut myled(LED1);

int main() {
while(1) {
myled = 1;
// printf("LED On\r\n");
wait(0.2);
myled = 0;
// printf("LED Off \r\n");
wait(0.2);
}
}
1 change: 1 addition & 0 deletions Flow-Control/Busy-Wait/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7
3 changes: 3 additions & 0 deletions Flow-Control/Interrupt-Button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Flow Control: Interrupt button example

A digital input monitoring implementation with an interrupt.
17 changes: 17 additions & 0 deletions Flow-Control/Interrupt-Button/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "mbed.h"

InterruptIn button(SW1);
DigitalOut led(LED1);
DigitalOut heartbeat(LED2);

void toggle() {
led = !led;
}

int main() {
button.rise(&toggle); // call toggle function on the rising edge
while(1) { // wait around, interrupts will interrupt this!
heartbeat = !heartbeat;
wait(0.25);
}
}
1 change: 1 addition & 0 deletions Flow-Control/Interrupt-Button/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7
3 changes: 3 additions & 0 deletions Flow-Control/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Flow Control

The examples in this folder utilize Blinky in order to explore flow control and task management in Arm Mbed OS applications.
3 changes: 3 additions & 0 deletions Flow-Control/Thread/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Flow Control: Thread example

A threaded Blinky implementation.
23 changes: 23 additions & 0 deletions Flow-Control/Thread/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
Thread thread;

void led2_thread() {
while (true) {
led2 = !led2;
wait(1);
}
}

int main() {
// Create a thread to execute the function led2_thread
thread.start(led2_thread);
// led2_thread is executing concurrently with main at this point

while (true) {
led1 = !led1;
wait(0.5);
}
}
1 change: 1 addition & 0 deletions Flow-Control/Thread/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7
3 changes: 3 additions & 0 deletions Flow-Control/Ticker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Flow Control: Ticker example

A ticker Blinky implementation.
20 changes: 20 additions & 0 deletions Flow-Control/Ticker/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "mbed.h"

Ticker flipper;
DigitalOut led1(LED1);
DigitalOut led2(LED2);

void flip() {
led2 = !led2;
}

int main() {
led2 = 1;
flipper.attach(&flip, 2.0); // call flip function every 2 seconds

// spin in a main loop. flipper will interrupt it to call flip
while(1) {
led1 = !led1;
wait(0.2);
}
}
1 change: 1 addition & 0 deletions Flow-Control/Ticker/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7
1 change: 1 addition & 0 deletions IdleLoop/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/ARMmbed/mbed-os/#c53d51fe9220728bf8ed27afe7afc1ecc3f6f5d7