~
Dependencies: mbed SimpleRGB mbed-rtos 4DGL-uLCD-SE SDFileSystem wave_player
main.cpp@4:4792f0db029a, 2016-10-11 (annotated)
- Committer:
- fkhan39
- Date:
- Tue Oct 11 01:18:40 2016 +0000
- Revision:
- 4:4792f0db029a
- Parent:
- 3:641770225c44
- Child:
- 5:420cda7cbfc5
ulcd commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kswanson31 | 0:51d88b4e2b23 | 1 | #include "mbed.h" |
kswanson31 | 0:51d88b4e2b23 | 2 | #include "rtos.h" |
fkhan39 | 4:4792f0db029a | 3 | #include "uLCD_4DGL.h" |
kswanson31 | 1:ff69d2d97a2c | 4 | #include "SimpleRGB.h" |
kswanson31 | 1:ff69d2d97a2c | 5 | |
kswanson31 | 1:ff69d2d97a2c | 6 | #define SECOND 1000 // used with threads |
kswanson31 | 3:641770225c44 | 7 | DigitalOut led(LED1); // test led |
kswanson31 | 0:51d88b4e2b23 | 8 | |
fkhan39 | 4:4792f0db029a | 9 | uLCD_4DGL lcd(p13,p14,p12); |
kswanson31 | 3:641770225c44 | 10 | /* 1 init/declare |
kswanson31 | 1:ff69d2d97a2c | 11 | |
kswanson31 | 0:51d88b4e2b23 | 12 | Ticker first; |
kswanson31 | 0:51d88b4e2b23 | 13 | Ticker second; |
kswanson31 | 0:51d88b4e2b23 | 14 | Ticker third; |
kswanson31 | 0:51d88b4e2b23 | 15 | Ticker fourth; |
kswanson31 | 0:51d88b4e2b23 | 16 | DigitalOut led1(LED1); |
kswanson31 | 0:51d88b4e2b23 | 17 | DigitalOut led2(LED2); |
kswanson31 | 0:51d88b4e2b23 | 18 | DigitalOut led3(LED3); |
kswanson31 | 0:51d88b4e2b23 | 19 | DigitalOut led4(LED4); |
kswanson31 | 0:51d88b4e2b23 | 20 | |
kswanson31 | 0:51d88b4e2b23 | 21 | void one() { // attached to ticker object. will be called after time given |
kswanson31 | 0:51d88b4e2b23 | 22 | led1 = !led1; // flip the value of the led |
kswanson31 | 0:51d88b4e2b23 | 23 | } // nothing returned |
kswanson31 | 0:51d88b4e2b23 | 24 | |
kswanson31 | 0:51d88b4e2b23 | 25 | void two() { |
kswanson31 | 0:51d88b4e2b23 | 26 | led2 = !led2; |
kswanson31 | 0:51d88b4e2b23 | 27 | } |
kswanson31 | 0:51d88b4e2b23 | 28 | |
kswanson31 | 0:51d88b4e2b23 | 29 | void three() { |
kswanson31 | 0:51d88b4e2b23 | 30 | led3 = !led3; |
kswanson31 | 0:51d88b4e2b23 | 31 | } |
kswanson31 | 0:51d88b4e2b23 | 32 | |
fkhan39 | 2:c64bfb83fe76 | 33 | void four() { |
kswanson31 | 0:51d88b4e2b23 | 34 | led4 = !led4; |
kswanson31 | 0:51d88b4e2b23 | 35 | } |
kswanson31 | 1:ff69d2d97a2c | 36 | |
kswanson31 | 3:641770225c44 | 37 | */// - 1 |
kswanson31 | 0:51d88b4e2b23 | 38 | |
kswanson31 | 1:ff69d2d97a2c | 39 | |
kswanson31 | 3:641770225c44 | 40 | /* 2 init/declare */ |
kswanson31 | 1:ff69d2d97a2c | 41 | |
kswanson31 | 1:ff69d2d97a2c | 42 | // lcd thread |
kswanson31 | 0:51d88b4e2b23 | 43 | void uLCD_reboot_thread(void const *args) { |
kswanson31 | 0:51d88b4e2b23 | 44 | // show reboot process, associated with clip of apple restart |
kswanson31 | 1:ff69d2d97a2c | 45 | while (true) { |
kswanson31 | 0:51d88b4e2b23 | 46 | // lock, print 'Rebooting!' to uLCD with "progress_bar" underneath |
fkhan39 | 4:4792f0db029a | 47 | lcd.text_string("Rebooting", 2, 5, FONT_7X8, WHITE); |
kswanson31 | 0:51d88b4e2b23 | 48 | // draw progress bar 8 sec |
fkhan39 | 4:4792f0db029a | 49 | std::string progress("|"); |
fkhan39 | 4:4792f0db029a | 50 | for (int i = 0; i < 8; i++) { |
fkhan39 | 4:4792f0db029a | 51 | lcd.text_string(progress, 2, 6, FONT_7X8, WHITE); |
fkhan39 | 4:4792f0db029a | 52 | progress += '|'; |
fkhan39 | 4:4792f0db029a | 53 | wait(SECOND); |
fkhan39 | 4:4792f0db029a | 54 | } |
kswanson31 | 0:51d88b4e2b23 | 55 | // draw an ascii 'apple' |
fkhan39 | 4:4792f0db029a | 56 | lcd.text_string("(_`_)", 2, 5, FONT_7X8, WHITE); |
fkhan39 | 4:4792f0db029a | 57 | lcd.text_string("", 2, 6, FONT_7X8, WHITE); |
kswanson31 | 0:51d88b4e2b23 | 58 | // unlock, wait for 52 |
fkhan39 | 4:4792f0db029a | 59 | wait(52*SECOND); |
kswanson31 | 0:51d88b4e2b23 | 60 | } |
kswanson31 | 0:51d88b4e2b23 | 61 | } |
kswanson31 | 0:51d88b4e2b23 | 62 | |
kswanson31 | 1:ff69d2d97a2c | 63 | // lcd thread |
kswanson31 | 0:51d88b4e2b23 | 64 | void uLCD_status_thread(void const *args) { |
kswanson31 | 0:51d88b4e2b23 | 65 | // show time with smile, frown, sad face at top right |
fkhan39 | 4:4792f0db029a | 66 | set_time(1476146921); |
kswanson31 | 1:ff69d2d97a2c | 67 | while (true) { |
kswanson31 | 0:51d88b4e2b23 | 68 | // lock, update time at top right with smiley at top left |
fkhan39 | 4:4792f0db029a | 69 | time_t seconds = time(NULL); |
fkhan39 | 4:4792f0db029a | 70 | char buffer[32]; |
fkhan39 | 4:4792f0db029a | 71 | strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
fkhan39 | 4:4792f0db029a | 72 | lcd.text_string(buffer, 5, 1, FONT_7X8, RED); |
fkhan39 | 4:4792f0db029a | 73 | lcd.text_string(":-)", 1, 1, FONT_7X8, WHITE); |
kswanson31 | 0:51d88b4e2b23 | 74 | // unlock, wait for 20 sec |
fkhan39 | 4:4792f0db029a | 75 | wait(20*SECOND); |
fkhan39 | 4:4792f0db029a | 76 | // lock, change to frown |
fkhan39 | 4:4792f0db029a | 77 | lcd.text_string(">:|", 1, 1, FONT_7X8, WHITE); |
fkhan39 | 4:4792f0db029a | 78 | // unlock, wait for 20 sec |
fkhan39 | 4:4792f0db029a | 79 | wait(20*SECOND); |
kswanson31 | 0:51d88b4e2b23 | 80 | // lock, change to sad |
fkhan39 | 4:4792f0db029a | 81 | lcd.text_string(":-(", 1, 1, FONT_7X8, WHITE); |
kswanson31 | 0:51d88b4e2b23 | 82 | // unlock, wait for 20 sec |
fkhan39 | 4:4792f0db029a | 83 | wait(20*SECOND); |
kswanson31 | 0:51d88b4e2b23 | 84 | } |
kswanson31 | 0:51d88b4e2b23 | 85 | } |
kswanson31 | 0:51d88b4e2b23 | 86 | |
kswanson31 | 1:ff69d2d97a2c | 87 | RGBLed rgbLED(p21, p22, p23); // object to use the RGB LED |
kswanson31 | 1:ff69d2d97a2c | 88 | const LightColor green(0.0, 0.8, 0.0); // adjust brightness for green |
kswanson31 | 1:ff69d2d97a2c | 89 | const LightColor yellow(1.0, 0.8, 0.0); |
kswanson31 | 1:ff69d2d97a2c | 90 | const LightColor orange(1.0, 0.4, 0.0); |
kswanson31 | 1:ff69d2d97a2c | 91 | const LightColor red(1.0,0.0,0.0); |
kswanson31 | 1:ff69d2d97a2c | 92 | const LightColor violet(1.0, 0.0, 0.8); |
kswanson31 | 1:ff69d2d97a2c | 93 | const LightColor blue(0.0, 0.0, 1.0); |
kswanson31 | 1:ff69d2d97a2c | 94 | |
kswanson31 | 1:ff69d2d97a2c | 95 | // rgb led thread |
kswanson31 | 0:51d88b4e2b23 | 96 | void rainbow_led_thread(void const *args) { |
kswanson31 | 1:ff69d2d97a2c | 97 | // reboot with white (6 sec), then cycle through apple colors (54 sec) |
kswanson31 | 1:ff69d2d97a2c | 98 | while (true) { |
kswanson31 | 1:ff69d2d97a2c | 99 | rgbLED.write(1.0, 1.0, 1.0); // bright white |
kswanson31 | 1:ff69d2d97a2c | 100 | Thread::wait(2 * SECOND); |
kswanson31 | 1:ff69d2d97a2c | 101 | // dim to nothing over 4 seconds |
kswanson31 | 1:ff69d2d97a2c | 102 | for (float c = 1.0; c > 0.0; c = c - 0.01) { |
kswanson31 | 1:ff69d2d97a2c | 103 | rgbLED.write(c, c, c); |
kswanson31 | 1:ff69d2d97a2c | 104 | Thread::wait(40); // 40 * 100 = 4000 = 4 secs |
kswanson31 | 1:ff69d2d97a2c | 105 | } |
kswanson31 | 1:ff69d2d97a2c | 106 | // rotate through other colors over 54 seconds |
kswanson31 | 1:ff69d2d97a2c | 107 | rgbLED = green; |
kswanson31 | 1:ff69d2d97a2c | 108 | Thread::wait(9 * SECOND); |
kswanson31 | 1:ff69d2d97a2c | 109 | rgbLED = yellow; |
kswanson31 | 1:ff69d2d97a2c | 110 | Thread::wait(9 * SECOND); |
kswanson31 | 1:ff69d2d97a2c | 111 | rgbLED = orange; |
kswanson31 | 1:ff69d2d97a2c | 112 | Thread::wait(9 * SECOND); |
kswanson31 | 1:ff69d2d97a2c | 113 | rgbLED = red; |
kswanson31 | 1:ff69d2d97a2c | 114 | Thread::wait(9 * SECOND); |
kswanson31 | 1:ff69d2d97a2c | 115 | rgbLED = violet; |
kswanson31 | 1:ff69d2d97a2c | 116 | Thread::wait(9 * SECOND); |
kswanson31 | 1:ff69d2d97a2c | 117 | rgbLED = blue; |
kswanson31 | 1:ff69d2d97a2c | 118 | Thread::wait(9 * SECOND); |
kswanson31 | 0:51d88b4e2b23 | 119 | } |
kswanson31 | 0:51d88b4e2b23 | 120 | } |
kswanson31 | 3:641770225c44 | 121 | // - 2 |
kswanson31 | 0:51d88b4e2b23 | 122 | |
kswanson31 | 1:ff69d2d97a2c | 123 | |
kswanson31 | 0:51d88b4e2b23 | 124 | int main() { |
kswanson31 | 3:641770225c44 | 125 | /* 1 calls |
kswanson31 | 0:51d88b4e2b23 | 126 | led1 = 1, led2 = 1, led3 = 1, led4 = 1; |
kswanson31 | 0:51d88b4e2b23 | 127 | |
kswanson31 | 0:51d88b4e2b23 | 128 | first.attach(&one, 1.0); // attach the function and when to call it |
kswanson31 | 0:51d88b4e2b23 | 129 | second.attach(&two, 2.0); |
kswanson31 | 0:51d88b4e2b23 | 130 | third.attach(&three, 3.0); |
kswanson31 | 0:51d88b4e2b23 | 131 | fourth.attach(&four, 4.0); |
kswanson31 | 3:641770225c44 | 132 | */// - 1 |
kswanson31 | 0:51d88b4e2b23 | 133 | |
kswanson31 | 1:ff69d2d97a2c | 134 | |
kswanson31 | 3:641770225c44 | 135 | /* 2 calls */ |
kswanson31 | 3:641770225c44 | 136 | //Thread thread2(uLCD_reboot_thread); |
kswanson31 | 3:641770225c44 | 137 | //Thread thread3(uLCD_status_thread); |
kswanson31 | 1:ff69d2d97a2c | 138 | Thread thread4(rainbow_led_thread); |
kswanson31 | 3:641770225c44 | 139 | // - 2 |
kswanson31 | 1:ff69d2d97a2c | 140 | |
kswanson31 | 1:ff69d2d97a2c | 141 | |
kswanson31 | 3:641770225c44 | 142 | led = 1; |
kswanson31 | 3:641770225c44 | 143 | |
kswanson31 | 1:ff69d2d97a2c | 144 | while(true) { |
kswanson31 | 3:641770225c44 | 145 | /* 2 speaker 'thread' calls |
kswanson31 | 0:51d88b4e2b23 | 146 | // speaker plays mac reboot sound, error sound occasionally |
kswanson31 | 0:51d88b4e2b23 | 147 | // play reboot sound |
kswanson31 | 0:51d88b4e2b23 | 148 | // wait 20 |
kswanson31 | 0:51d88b4e2b23 | 149 | // error |
kswanson31 | 0:51d88b4e2b23 | 150 | // wait 20 |
kswanson31 | 0:51d88b4e2b23 | 151 | // error |
kswanson31 | 0:51d88b4e2b23 | 152 | // wait 20 |
kswanson31 | 3:641770225c44 | 153 | */// - 2 |
kswanson31 | 3:641770225c44 | 154 | |
kswanson31 | 3:641770225c44 | 155 | |
kswanson31 | 3:641770225c44 | 156 | // thread testing |
kswanson31 | 3:641770225c44 | 157 | led = !led; |
kswanson31 | 3:641770225c44 | 158 | Thread::wait(2000); |
kswanson31 | 3:641770225c44 | 159 | led = !led; |
kswanson31 | 3:641770225c44 | 160 | Thread::wait(1000); |
kswanson31 | 3:641770225c44 | 161 | led = !led; |
kswanson31 | 3:641770225c44 | 162 | Thread::wait(500); |
kswanson31 | 3:641770225c44 | 163 | // - test |
kswanson31 | 3:641770225c44 | 164 | |
kswanson31 | 0:51d88b4e2b23 | 165 | } // interupts will occur automatically |
kswanson31 | 0:51d88b4e2b23 | 166 | } |