Optimized Knight Rider using Array and for loops

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
bromand
Date:
Sun Jun 26 20:14:36 2011 +0000
Parent:
0:7077b6e6d693
Commit message:
1.0.0.1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7077b6e6d693 -r 2664d12843c6 main.cpp
--- a/main.cpp	Wed Jun 22 22:42:12 2011 +0000
+++ b/main.cpp	Sun Jun 26 20:14:36 2011 +0000
@@ -1,38 +1,41 @@
+//Include mbed header file which contains the definition of DigitalOut class. 
 #include "mbed.h"
+//Include TextLCD header file which contains the definition of TextLCD class. 
 #include "TextLCD.h"
 
-
+//Initialize DigitalOut array with for LEDs
 DigitalOut array[4] = {LED1,LED2,LED3,LED4};
-
+//Initialize TextLCD with the correct pins
 TextLCD lcd(p24, p26, p27, p28, p29, p30);
 
-#define WAIT_time 0.04
-#define D() wait(WAIT_time)
-
-
+//Main function
 int main() 
 {
+    //Clear the LCD display
     lcd.cls();
+    //Locate Row 0 Column in the LCD display
     lcd.locate(0, 0);
+    //Print my name
     lcd.printf("DANIEL BROMAND");
-
+    //Locate Row 1 column 0 in the LCD display
     lcd.locate(0, 1);
+    //Print Knight Rider
     lcd.printf("Knight Rider");
-    
+    //First for loop to insure initialization of all LEDs to 1    
     for(int i=0;i<4;i++)
     {
         array[i] = 1;
     }
-
+    //Loop forever
     while(true) 
     {
-        for(int i=0;i<16;i++)
+        //Iterate through all LEDs 
+        //For each LED set the opposite of what it currently has. 
+        for(int i=0;i<4;i++)
         {
-            if (i%4)
-            {
-                array[i] = !array[i];
-                D();
-            }
-        }        
-    }
-}
+            array[i] = !array[i];
+            //wait for 400ms. 
+            wait(0.4);
+        }//End of for loop        
+    }//End of while loop
+}//End of Main function