I had this programming problem when learning arduino. I had a pair of 9 leds connected to the digital pins and want the first and last leds to light up that the next ones and meet at the middle than bump back to the ends again. To overview the 2 edges of my row of less light up than they meet at the middle and go back to the edge again. If it helps it was the second chapter in the book Beginning Arduino by Michael MCRoberts (a exercise). This was my code but it does not work right.
byte ledPin[] = {4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13};
int direction = 1;
int currentLed = 0;
int directionl = -1;
int hi = 9;
void setup() {
for (int x=0; x < 10 ; x++) {
pinMode(ledPin[x], OUTPUT);
}
}
void loop() {
delay(250);
changeLED();
}
void changeLED() {
for (int x=0; x < 10 ; x++) {
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLed], HIGH);
digitalWrite(ledPin[hi], HIGH);
currentLed += direction;
hi += directionl;
if(currentLed== 5){direction== -1;}
if(currentLed == 0){direction== 1;}
if(hi== 6){directionl== 1;}
if(hi== 9){directionl== -1;}
}
when I enter the code my project does what I want it to do but after the first time it lights up random Leds.
PLS HELP and THANKS
Moderator edit: CODE TAGS. What's so difficult?