chase led

byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Create array for LED pins
int ledDelay(65); // delay between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
void setup() {
for (int x=0; x<10; x++) { // set all pins to output
pinMode(ledPin[x], 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++) { // turn off all LED's
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLED], HIGH); // turn on the current LED
currentLED += direction; // increment by the direction value
// change direction if we reach the end
if (currentLED == 9) {direction = -1;}
if (currentLED == 0) {direction = 1;}
}

If I want to make the LED effect like that below ,what do I should to do ?
• Exercise 1: Get the LEDs at BOTH ends of the strip to start as on, then move
towards each other, appear to bounce off each other, and then move back to the
end.
• Exercise 2: Make a bouncing ball effect 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 9th LED, then back down, then up to the 8th,
and so on to simulate a bouncing ball losing momentum after each bounce.

exercise 1 :
It is almost the same code, but now you have 2 currentleds :slight_smile:

exercise 2:
define the max height, which change after every bounce.

robtillaart:
exercise 1 :
It is almost the same code, but now you have 2 currentleds :slight_smile:

exercise 2:
define the max height, which change after every bounce.

I have tried this as you said in exercise 1 ,add another currentled,but it doesn't work .just 2 currentleds ,no other direction ?
can you give me a detail about these two exercises?

Have a look at my website to find solutions to exercise 1-10 :wink:

just 2 currentleds ,no other direction ?

"Started has thinking", Yoda

Thanks a lot