I would like leds to light from left to right and then right to left in the continuous loop when I press the button.When I press the button again, lights should go off completely. I wrote the code below, it works when I press the button first time. However, when I press the button again, leds don't stop.
Any idea what's wrong with my code below.
Welcome to the Forum. Please read the two posts by Nick Gammon about the guidelines for posting to the Forum, especially using code tags for source code listings.
In your present code, how is the statement
pinMode (ledPin, OUTPUT);
supposed to affect ledPin elements if no array subscript is given? Also, why is inputPin even in the for loop?
@Yellow GTM: I can understand the for loop in setup() if it were written:
for (int i = 0; i<3; i++)
pinMode (ledPin[i], OUTPUT);
but he left the array subscripts out and does it again in loop(), yet uses a subscript in one of his calls to digitalWrite(). Perhaps there's a syntactic shortcut I don't know about...