Daniel Bromand
/
KnightRiderOptimized
Optimized Knight Rider using Array and for loops
main.cpp@1:2664d12843c6, 2011-06-26 (annotated)
- Committer:
- bromand
- Date:
- Sun Jun 26 20:14:36 2011 +0000
- Revision:
- 1:2664d12843c6
- Parent:
- 0:7077b6e6d693
1.0.0.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bromand | 1:2664d12843c6 | 1 | //Include mbed header file which contains the definition of DigitalOut class. |
bromand | 0:7077b6e6d693 | 2 | #include "mbed.h" |
bromand | 1:2664d12843c6 | 3 | //Include TextLCD header file which contains the definition of TextLCD class. |
bromand | 0:7077b6e6d693 | 4 | #include "TextLCD.h" |
bromand | 0:7077b6e6d693 | 5 | |
bromand | 1:2664d12843c6 | 6 | //Initialize DigitalOut array with for LEDs |
bromand | 0:7077b6e6d693 | 7 | DigitalOut array[4] = {LED1,LED2,LED3,LED4}; |
bromand | 1:2664d12843c6 | 8 | //Initialize TextLCD with the correct pins |
bromand | 0:7077b6e6d693 | 9 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
bromand | 0:7077b6e6d693 | 10 | |
bromand | 1:2664d12843c6 | 11 | //Main function |
bromand | 0:7077b6e6d693 | 12 | int main() |
bromand | 0:7077b6e6d693 | 13 | { |
bromand | 1:2664d12843c6 | 14 | //Clear the LCD display |
bromand | 0:7077b6e6d693 | 15 | lcd.cls(); |
bromand | 1:2664d12843c6 | 16 | //Locate Row 0 Column in the LCD display |
bromand | 0:7077b6e6d693 | 17 | lcd.locate(0, 0); |
bromand | 1:2664d12843c6 | 18 | //Print my name |
bromand | 0:7077b6e6d693 | 19 | lcd.printf("DANIEL BROMAND"); |
bromand | 1:2664d12843c6 | 20 | //Locate Row 1 column 0 in the LCD display |
bromand | 0:7077b6e6d693 | 21 | lcd.locate(0, 1); |
bromand | 1:2664d12843c6 | 22 | //Print Knight Rider |
bromand | 0:7077b6e6d693 | 23 | lcd.printf("Knight Rider"); |
bromand | 1:2664d12843c6 | 24 | //First for loop to insure initialization of all LEDs to 1 |
bromand | 0:7077b6e6d693 | 25 | for(int i=0;i<4;i++) |
bromand | 0:7077b6e6d693 | 26 | { |
bromand | 0:7077b6e6d693 | 27 | array[i] = 1; |
bromand | 0:7077b6e6d693 | 28 | } |
bromand | 1:2664d12843c6 | 29 | //Loop forever |
bromand | 0:7077b6e6d693 | 30 | while(true) |
bromand | 0:7077b6e6d693 | 31 | { |
bromand | 1:2664d12843c6 | 32 | //Iterate through all LEDs |
bromand | 1:2664d12843c6 | 33 | //For each LED set the opposite of what it currently has. |
bromand | 1:2664d12843c6 | 34 | for(int i=0;i<4;i++) |
bromand | 0:7077b6e6d693 | 35 | { |
bromand | 1:2664d12843c6 | 36 | array[i] = !array[i]; |
bromand | 1:2664d12843c6 | 37 | //wait for 400ms. |
bromand | 1:2664d12843c6 | 38 | wait(0.4); |
bromand | 1:2664d12843c6 | 39 | }//End of for loop |
bromand | 1:2664d12843c6 | 40 | }//End of while loop |
bromand | 1:2664d12843c6 | 41 | }//End of Main function |