Nathan Yonkee / Mbed OS Seeed_Grove_4_Digit_Display_Clock

Dependencies:   Data_Clock_Pair Seeed_Chainable_LED Seeed_Four_Digit_Disp Seeed_IR_Temp_Sensor Seeed_Led_Bar

Fork of Seeed_Grove_4_Digit_Display_Clock by Seeed

Files at this revision

API Documentation at this revision

Comitter:
tulanthoar
Date:
Sun May 21 13:33:34 2017 -0600
Parent:
16:cebc9f55d2a6
Child:
18:904d89c7811a
Commit message:
use infinite for loop and embed the delay in the loop declaration

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 18 10:48:12 2017 -0600
+++ b/main.cpp	Sun May 21 13:33:34 2017 -0600
@@ -11,19 +11,19 @@
 namespace  {
 
 Serial pc(SERIAL_TX, SERIAL_RX);
-DigitalOut led(PF_12);
 AnalogIn knob(PA_3);
 
-void led_thread() {
-    while(1) {
-        led = !led;
-        Thread::wait(1000);
+void blink_led() {
+    for(DigitalOut led(PF_12);; Thread::wait(1000) ) {
+        led = !led
     }
 }
 } // namespace
 
 int main() {
     pc.printf("\n\nstarting algorithm\n\n");
+    Thread heartbeat;
+    heartbeat.start(callback(blink_led));
     DataClockPair chainablePins, rgbPins, qTouchPins, dispPins, ledBarPins, surrDispPins;
     surrDispPins.dataPin = PG_0;
     surrDispPins.clockPin = PG_1;
@@ -44,9 +44,6 @@
     SeeedChainableLED led_chain(chainablePins);
     SeeedChainableLED rgb_led(rgbPins);
 
-    Thread blinky;
-    blinky.start(callback(led_thread));
-
     disp.set_digit(0,0);
     int knob_led_bar[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
     ledBar.ten_on();
@@ -54,7 +51,7 @@
     led_chain.turn_on();
     led_chain.set_color_rgb(100,50,0);
     rgb_led.set_color_rgb(50,200,10);
-    while (1) {
+    for (;; Thread::wait(1000) ) {
         qTouch.key_touch(&pc);
         surrDisp.set_integer(floor(IRTempSensor::measureObjectTemp(PA_3, PC_0)));
         auto led_frac = knob.read();
@@ -72,7 +69,6 @@
         int eightBitInput = led_frac * 255;
         led_chain.set_color_rgb(eightBitInput, eightBitInput, eightBitInput);
         rgb_led.set_color_rgb(50,eightBitInput,10);
-        Thread::wait(1000);
     }
     return 1;
 }