Now I want to give a gift to my friend Shahil Bhatkar who has asked me how to make chase as much as 5 led. I made this program run using a simulator app called SimulIDE. You can download here.
Please use this program for your arduino:
//------------------------------------------------------------------------
// Program
//------------------------------------------------------------------------
byte ledPin [] = {9, 10, 11, 12, 13}; //Set pin for LED
int ledDelay = 200; //set delay for chase
int direction = 1;
int currentLed = 0;
unsigned long changeTime;
void setup() {
for (int x = 0; x < 5; x++) { //Set all pin as Output
pinMode (ledPin[x], OUTPUT);
}
changeTime = millis();
}
void loop() {
if ((millis() - changeTime) > ledDelay) {
changeLED();
changeTime = millis();
}
}
void changeLED() {
// turn off all LED's
for (int x = 0; x < 5; x++) {
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLed], HIGH);
currentLed += direction;
if (currentLed == 4) {
direction = -1;
}
if (currentLed == 0) {
direction = 1;
}
}
Video:
Share This :
0 comments