Monday, September 10, 2012
KATIRIA & NISA| CODE
byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; //telling you which pin the LED is plugged into
int ledDelay(65); //what the delay is between LEDs
int direction = 1; //direction in which the light is jumping between LEDs
int currentLED = 0; //the current LED being processed
unsigned long changeTime; //changing time with a "long" data type
void setup() { //setup the program
for(int x=0; x<10; x++) { //while these conditions are true [starting at x=0 while x is less than ten, add 1]
pinMode(ledPin[x], OUTPUT);} //tells you if the pin is set as input or output [telling LED to turn on or off]
changeTime = millis(); //change time to milliseconds
}
void loop() { //tells program to constantly loop
if((millis() - changeTime) > ledDelay) { //if ((millis() - changeTime) > ledDelay) is true, change the LED and change the time to milliseconds
changeLED(); //see above
changeTime = millis(); //see above
}
}
void changeLED() { //begin when the "if" statement is true
for (int x = 0; x<10; x++) { //while these conditions are true [starting at x=0 while x is less than ten, add 1]
digitalWrite(ledPin[x], LOW); //turn the LED in the pin off
}
digitalWrite(ledPin[currentLED], HIGH); // is telling you to turn in on when the for statement is false
currentLED += direction; // Change dirrection
if(currentLED == 9) {direction = -1;} // when it reaches the 9 LED dirrecion reverses
if (currentLED == 0) {direction = 1;} // when it reaches LED 0 change dirrection foward
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment