~
Dependencies: mbed SimpleRGB mbed-rtos 4DGL-uLCD-SE SDFileSystem wave_player
Diff: main.cpp
- Revision:
- 1:ff69d2d97a2c
- Parent:
- 0:51d88b4e2b23
- Child:
- 2:c64bfb83fe76
--- a/main.cpp Sun Oct 09 23:30:00 2016 +0000 +++ b/main.cpp Mon Oct 10 01:18:11 2016 +0000 @@ -1,7 +1,11 @@ #include "mbed.h" #include "rtos.h" +#include "SimpleRGB.h" + +#define SECOND 1000 // used with threads /* 1 init/declare + Ticker first; Ticker second; Ticker third; @@ -26,12 +30,16 @@ void fourth() { led4 = !led4; } + */// - 1 + /* 2 init/declare */ + +// lcd thread void uLCD_reboot_thread(void const *args) { // show reboot process, associated with clip of apple restart - while (1) { + while (true) { // lock, print 'Rebooting!' to uLCD with "progress_bar" underneath // draw progress bar 8 sec // draw an ascii 'apple' @@ -39,9 +47,10 @@ } } +// lcd thread void uLCD_status_thread(void const *args) { // show time with smile, frown, sad face at top right - while (1) { + while (true) { // lock, update time at top right with smiley at top left // unlock, wait for 20 sec // lock, change to frown @@ -51,20 +60,43 @@ } } +RGBLed rgbLED(p21, p22, p23); // object to use the RGB LED +const LightColor green(0.0, 0.8, 0.0); // adjust brightness for green +const LightColor yellow(1.0, 0.8, 0.0); +const LightColor orange(1.0, 0.4, 0.0); +const LightColor red(1.0,0.0,0.0); +const LightColor violet(1.0, 0.0, 0.8); +const LightColor blue(0.0, 0.0, 1.0); + +// rgb led thread void rainbow_led_thread(void const *args) { - // reboot with white, then cycle through apple rainbow colors - while (1) { - // bright white, dim to nothing over 4 sec - // green - // yellow - // orange - // red - // purple - // blue + // reboot with white (6 sec), then cycle through apple colors (54 sec) + while (true) { + rgbLED.write(1.0, 1.0, 1.0); // bright white + Thread::wait(2 * SECOND); + // dim to nothing over 4 seconds + for (float c = 1.0; c > 0.0; c = c - 0.01) { + rgbLED.write(c, c, c); + Thread::wait(40); // 40 * 100 = 4000 = 4 secs + } + // rotate through other colors over 54 seconds + rgbLED = green; + Thread::wait(9 * SECOND); + rgbLED = yellow; + Thread::wait(9 * SECOND); + rgbLED = orange; + Thread::wait(9 * SECOND); + rgbLED = red; + Thread::wait(9 * SECOND); + rgbLED = violet; + Thread::wait(9 * SECOND); + rgbLED = blue; + Thread::wait(9 * SECOND); } } // - 2 + int main() { /* 1 calls led1 = 1, led2 = 1, led3 = 1, led4 = 1; @@ -75,7 +107,15 @@ fourth.attach(&four, 4.0); */// - 1 - while(1) { + + /* 2 calls */ + Thread thread2(uLCD_reboot_thread); + Thread thread3(uLCD_status_thread); + Thread thread4(rainbow_led_thread); + // - 2 + + + while(true) { /* 2 speaker 'thread' calls */ // speaker plays mac reboot sound, error sound occasionally // play reboot sound