First mbed program example and usage

Dependencies:   mbed

Fork of HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
efoster79
Date:
Sat Oct 18 14:20:50 2014 +0000
Parent:
2:9debb94a4c8c
Child:
4:48af6a1a72c6
Commit message:
Testing loop methods

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Oct 18 13:19:48 2014 +0000
+++ b/main.cpp	Sat Oct 18 14:20:50 2014 +0000
@@ -1,15 +1,26 @@
 #include "mbed.h"
 
-DigitalOut outled1(LED1);
-DigitalOut outled3(LED3);
+#define TOTAL_LEDS 4
+
+DigitalOut outleds[TOTAL_LEDS] = { LED1, LED2, LED3, LED4 };
 
 int main() {
+    
+    int last_selected = 1;
+    int i;
+    
     while(1) {
-        outled1 = 1;
-        outled3 = 0;
+        for(i = 0 ; i < TOTAL_LEDS; i++){
+            int value_to_check = i + 1;
+            if( value_to_check == last_selected){
+                outleds[i] = 1;
+            }else{
+                outleds[i] = 0;
+            }      
+        }
+        
         wait(1);
-        outled1= 0;
-        outled3 = 1;
-        wait(1);
+        if(last_selected++ >= TOTAL_LEDS)
+            last_selected = 1;    
     }
 }