Ken Segler
/
ezLCD4_mbed
Not Complete
Fork of Nucleo_rtos by
Diff: main.cpp
- Revision:
- 73:d3b295249699
- Child:
- 77:cd59ac40b3be
diff -r 83895f30f8f2 -r d3b295249699 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Apr 16 08:10:26 2015 +0000 @@ -0,0 +1,48 @@ +#include "mbed.h" +#include "rtos.h" + +DigitalOut led(LED1); + +InterruptIn button(USER_BUTTON); + +uint32_t button_pressed; +Thread *thread2; + +void button_press(void) +{ + thread2->signal_set(0x1); +} + +void led_thread(void const *argument) +{ + while (true) { + led = !led; + Thread::wait(1000); + } +} + +void button_thread(void const *argument) +{ + while (true) { + Thread::signal_wait(0x1); + button_pressed++; + } +} + +int main() +{ + Thread thread(led_thread); + thread2 = new Thread(button_thread); + + printf("mbed RTOS example\n"); + + button_pressed = 0; + button.fall(&button_press); + + while (true) { + Thread::wait(6000); + printf("During the last 6 seconds, the Button was pressed %d times\n", button_pressed); + fflush(stdout); + button_pressed = 0; + } +}