A modified version of the hello world program to run using RTOS threads. Also, it cycles through seven colors on the RGB LED while it's doing its thing.
Fork of frdm_helloworld by
Diff: main.cpp
- Revision:
- 3:fd99fd0c7e60
- Parent:
- 0:4f3ac9922229
- Child:
- 4:f52f79d2f703
--- a/main.cpp Mon Apr 07 20:10:53 2014 +0000 +++ b/main.cpp Tue Aug 23 01:00:23 2016 +0000 @@ -1,17 +1,20 @@ #include "mbed.h" +#include "rtos.h" DigitalOut led_red(LED_RED); DigitalOut led_green(LED_GREEN); +DigitalOut led_blue(LED_BLUE); DigitalIn sw2(SW2); DigitalIn sw3(SW3); Serial pc(USBTX, USBRX); -void check_sw2(void) +void check_sw2_thread(void const *args) { - if (sw2 == 0) { - pc.printf("SW2 button pressed. \n"); - led_red = 0; - led_green = 1; + while(true) { + if (sw2 == 0) { + pc.printf("SW2 button pressed. \n"); + } + Thread::wait(.3); } } @@ -19,8 +22,8 @@ { if (sw3 == 0) { pc.printf("SW3 button pressed. \n"); - led_green = 0; - led_red = 1; + //led_green = 0; + //led_red = 1; pc.printf("5 characters will be echoed. Start typing. \n"); for (uint32_t i = 0; i < 5; i++) { pc.putc(pc.getc()); @@ -30,15 +33,27 @@ } } -int main() { - led_green = 1; - led_red = 1; +int main() +{ + Thread thread(check_sw2_thread); + pc.baud(115200); pc.printf("Hello World from FRDM-K64F board.\n"); + int i = 1; while (true) { - check_sw2(); check_sw3(); - wait(0.3); + + i += 1; + if (i > 7) { + i = 1; + } + led_red = !(i & 0x01); + led_green = !(i & 0x02); + led_blue = !(i & 0x04); + //pc.printf("i = %d: R = %d; G = %d; B = %d\n", i, led_red.read(), led_green.read(), led_blue.read()); + + wait(0.1); + } }