LED CHASER problem ?

i was reading Beginning Arduino, 2nd Edition and in 3rd chapter i came across led chasers there i completed first and second project this is the code written in book .

now my problem
i want to code a chaser with 10 leds from 4 to 13

and program in such a way that led at 4 and 13 starts together and move towards each other and after getting in middle each bounces of each other and move back in the same way i need code :frowning:

// Project 5 - LED Chase Effect
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;}
}

The first thing to do is to edit your post, select the code and click the code tags icon (</>) top/left above the editor. The code will then at least be readable but I am not sure why the code you posted seems to contain a reference to a figure in the book.

Lol sorry forget to edit and thank you for reporting :)

OK, so you have 10 LEDS numbered 0 to 9 and want to turn on LED pairs 0/9, 1/8, 2/7, 3/6, 4/5

Note how the numbers of the pairs always adds up to 9. So if you have a variable that holds the number of the first LED in the pair, which you have, you can work out the number of the second one by subtracting the first number from 9 and can turn on both of them.

UKHeliBob: OK, so you have 10 LEDS numbered 0 to 9 and want to turn on LED pairs 0/9, 1/8, 2/7, 3/6, 4/5

Note how the numbers of the pairs always adds up to 9. So if you have a variable that holds the number of the first LED in the pair, which you have, you can work out the number of the second one by subtracting the first number from 9 and can turn on both of them.

+1, also can you see how UHB did this? He looked for symmetry or a repeating pattern and then exploited it.