 # Interactive LED Chase Effect Excirses 2 Help!

I have to complete this given exercise: Make a bouncing ball affect by turning the LEDs so they are vertical, then make an LED start at the bottom, then “bounce” up to the top LED, then back to the bottom, then only up to the 89th LED, then back down, then up to the 8th, and so on to simulate a bouncing ball losing momentum after each bounce.

I currently have the base sketch below:

byte ledPin = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int ledDelay(65);
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
int potPin = 2;

void setup() {
for (int x=0; x<10; x++) { // set all pins to output
pinMode(ledPin, OUTPUT); }
changeTime = millis();
}

void loop() {
if ((millis() - changeTime) > ledDelay){ //if it has been ledDelay ms since last change
changeLED();
changeTime = millis();
}
}

void changeLED() {
for (int x=0; x<10; x++) {
digitalWrite(ledPin, LOW);

}
digitalWrite(ledPin[currentLED], HIGH);
currentLED += direction;
if(currentLED == 9) {direction = -1;}
if(currentLED == 0) {direction = 1;}
}

I don’t know where to go after this point. I need to set a maximum height and then let it go down 1 each time. I understand what needs to happen but I don’t know how to do them.
I hope someone can help show me a possible way to solve this exercise!

Thank you!

``````for (int x=0; x<10; x++) {
``````

Think hard about this line and what it does in your program. What does the value 10 represent? if you were to replace that constant with a variable and then decrement that variable from 10 each time changeLED() was called until you got to 0, would that accomplish what you want to do?