changing RGB color with the ticker function

Dependencies:   mbed-src

Fork of RGB_WIZwiki-W7500 by FOURNET Olivier

Revision:
4:fdb8fe5b6a74
Parent:
3:c97f8e12e04c
--- a/main.cpp	Mon May 09 20:31:16 2016 +0000
+++ b/main.cpp	Mon May 09 21:17:31 2016 +0000
@@ -11,15 +11,26 @@
 DigitalOut green(LED_GREEN);
 DigitalOut blue(LED_BLUE);
 
-int i;
+Ticker toggle_led_ticker;
+
+int i = 1;
 
-int main() {
-    while(1) {
-        for (i=1; i<7; i++) {
-            red = i & 1;
-            blue = i & 2;
-            green = i & 4;
-            wait(0.2);
-        }
+void toggle_led() 
+{
+    red = i & 1;
+    blue = i & 2;
+    green = i & 4;
+    ++i;
+    if(i == 7) i = 1;
+}
+
+int main() 
+{
+    // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms)
+    toggle_led_ticker.attach(&toggle_led, 0.5);
+    
+    while(true) 
+    { 
+     // Do other things...  
     }
 }
\ No newline at end of file