I am creating an LED bouncing ball effect with 10 LED's set up as an array, bouncing from 9 - 0 - 8 - 0 ...... and want to use a simple method of coding the last highest LED (-1) as the maximum 'bounce point' and then returning to 0 and so on. I am unsure of how to most effectively use the minus sign.
I did have success using the following code to get the LED to bounce from LED 10 back to 0 and then to 9:
void changeLED() {
// turn off all LED's
for (int x=0; x<10; x++) {
digitalWrite(ledPin[x], LOW);
}
// turn on the current LED
digitalWrite(ledPin[currentLED], HIGH);
// increment by the direction value
currentLED += direction;
if (currentLED == 0) {direction = 1;}
if (currentLED == currentLED1) {direction = -1;}
with int currentLED = 9
int currentLED1 = 8
However, trying to use this principle any futher does not seem to work.
Any help would be appreciated.