CITY1082 code example

Revision:
103:decc5a1b2e80
Parent:
102:17e6fc7c4be0
--- a/main.cpp	Tue Nov 05 09:15:05 2019 +0000
+++ b/main.cpp	Tue Nov 05 09:54:32 2019 +0000
@@ -12,8 +12,9 @@
 DigitalOut BlueLED(LED3);
 DigitalOut led1(LED4);
 DigitalOut led2(LED5);
+DigitalIn sw2(P0_4);
 
-#define SLEEP_TIME                  500 // (msec)
+#define SLEEP_TIME                  200 // (msec)
 #define PRINT_AFTER_N_LOOPS         20
 
 // main() runs in its own thread in the OS
@@ -24,12 +25,20 @@
     int count = 0;
     while (true) {
         // Blink LED and wait 0.5 seconds
-        led1 = !led1;
-        led2 = !led2;
-        RedLED = !RedLED;
-        GreenLED = !GreenLED;
-        BlueLED = !BlueLED;
-        thread_sleep_for(SLEEP_TIME);
+        if (sw2 == 1) {
+            led1= !led1;
+            thread_sleep_for(SLEEP_TIME);
+            led2 = !led2;
+        }
+        else {
+            thread_sleep_for(SLEEP_TIME);
+            RedLED = !RedLED;
+            thread_sleep_for(SLEEP_TIME);
+            GreenLED = !GreenLED;
+            thread_sleep_for(SLEEP_TIME);
+            BlueLED = !BlueLED;
+            thread_sleep_for(SLEEP_TIME);
+        }
 
         if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
             // Following the main thread wait, report on the current system status