Daniel Bromand
/
KnightRiderOptimized
Optimized Knight Rider using Array and for loops
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 //Include mbed header file which contains the definition of DigitalOut class. 00002 #include "mbed.h" 00003 //Include TextLCD header file which contains the definition of TextLCD class. 00004 #include "TextLCD.h" 00005 00006 //Initialize DigitalOut array with for LEDs 00007 DigitalOut array[4] = {LED1,LED2,LED3,LED4}; 00008 //Initialize TextLCD with the correct pins 00009 TextLCD lcd(p24, p26, p27, p28, p29, p30); 00010 00011 //Main function 00012 int main() 00013 { 00014 //Clear the LCD display 00015 lcd.cls(); 00016 //Locate Row 0 Column in the LCD display 00017 lcd.locate(0, 0); 00018 //Print my name 00019 lcd.printf("DANIEL BROMAND"); 00020 //Locate Row 1 column 0 in the LCD display 00021 lcd.locate(0, 1); 00022 //Print Knight Rider 00023 lcd.printf("Knight Rider"); 00024 //First for loop to insure initialization of all LEDs to 1 00025 for(int i=0;i<4;i++) 00026 { 00027 array[i] = 1; 00028 } 00029 //Loop forever 00030 while(true) 00031 { 00032 //Iterate through all LEDs 00033 //For each LED set the opposite of what it currently has. 00034 for(int i=0;i<4;i++) 00035 { 00036 array[i] = !array[i]; 00037 //wait for 400ms. 00038 wait(0.4); 00039 }//End of for loop 00040 }//End of while loop 00041 }//End of Main function
Generated on Tue Jul 26 2022 09:16:26 by 1.7.2