Nightrider effect question

Hello, I have a question about programming an Arduino uno.
I followed a tutorial which had an array in the software to control 10 LED's.
Now I want to make is:

LED 1 and 10 start on, move to the middle and bounce off then head back to where they started.

//LED Chase Effect
// Create array for LED pins
byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int ledDelay(65); // delay between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
void setup() {
// set all pins to output
for (int x=0; x<10; x++) {
pinMode(ledPin[x], OUTPUT); }
changeTime = millis();
}
void loop() {
// if it has been ledDelay ms since last change
if ((millis() - changeTime) > ledDelay) {
changeLED();
changeTime = millis();
}
}
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;
// change direction if we reach the end
if (currentLED == 9) {direction = -1;}
if (currentLED == 0) {direction = 1;}
}
// LED Chase Effect
// Create array for LED pins
byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};


int ledDelay(1000); // delay between changes
int direction = 1;
int currentLED = 0;
int currentLED2 = 10;
unsigned long changeTime;


void setup() {
// set all pins to output
for (int x=0; x<10; x++) {
pinMode(ledPin[x], OUTPUT); }
changeTime = millis();
}
void loop() {
// if it has been ledDelay ms since last change
if ((millis() - changeTime) > ledDelay) {
changeLED();
changeTime = millis();
}
}
void changeLED() {
// turn off all LED's
for (int x=0; x<10; x++) {
digitalWrite(ledPin[x], LOW);
}
// turn on the current LED for the first column
digitalWrite(ledPin[currentLED], HIGH);

//turn on the current LED for the second column
digitalWrite(ledPin[currentLED2], HIGH);

// increment by the direction value for the first column
currentLED += direction;
currentLED2 += direction;

// change direction if we reach the end the first column
if (currentLED == 0) {direction = 1;}
if (currentLED == 4) {direction = -1;}


// change direction if we reach the end the second colom
if (currentLED2 == 10) {direction = -1;}
if (currentLED2 == 6) {direction = 1;}


}

The first is the code from the tutorial, the second is mine.
I followed some things about arrays and such but I don't quite understand this very wel, could someone explain why the LED's won't start on both sides and then shift to the middle.
I can't figure out how to do this.

Since 'bouncing off' looks just like 'passing through' you can simplify quite a bit.

void changeLED()
    {
    static int led_index = 0;

    // Set the LED's
    for (int x=0; x<10; x++) 
        {
        digitalWrite(ledPin[x], x == led_index || x == (9 - led_index));
        }

    led_index++;
   if (led_index > 9)
        led_index = 0;
    }

Thank you for your reply, I will try this!
Is there a possibility that someone could explain why the code I used did not work?
I think it has something to do with the array, that it doesn't know where to start and end, is that true?

thanks again!

changeTime = millis();

Should include a time offset. For example - two seconds from now:

changeTime = millis() + 2000UL;

Alternate approach: forget the tutorial and have a look at my website. http://www.blinkenlight.net. If you want to blink LEDs that's the place to go.

Smokoo:
Is there a possibility that someone could explain why the code I used did not work?

currentLED += direction;
currentLED2 += direction;   // Since they go in opposite directions this should be -=
[/code

Hello, As I am new to Arduine, I was looking too for help about this code. I know this is an old topic but I reply anyway for other persons who are looking for help too. With the codes I found here and help from my friend Mike I could realize a complete working code. Thank you all.

Project_06B.ino (1.02 KB)

I was looking too for help about this code.

Just whining that you need help is rather useless. What help do you need? What does the code actually do? How does that differ from what you want?

Sorry, hope I attached the code the right way now.

  byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};    // Create array for LED pins
int ledDelay; // delay between changes
int direction = 1;
int currentLED = 0;
int currentLED2 = 9;
unsigned long changeTime;
int potPin = 2;    // select the input pin for the potentiometer

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

void loop() {
  ledDelay = analogRead(potPin); // read the value from the pot
  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
  digitalWrite(ledPin[currentLED2], HIGH); // turn on the current LED2

 

  currentLED += direction; // increment by the direction value
  currentLED2 -= direction; 
  // change direction if we reach the end
  if (currentLED == 4) {direction = -1;} //By making two groeps (each 5 LEDs) I avoid that the center LEDs stays on for timex2
  if (currentLED == 0) {direction = 1;}
  if (currentLED == 9) {direction = -1;}
  if (currentLED == 5) {direction = 1;}

  
}
[code]

PaulS:
Just whining that you need help is rather useless. What help do you need? What does the code actually do? How does that differ from what you want?

Hi PaulS, I don't need help for the code. It is working. I posted this to help other people.
What does the code? There are 10LEDs. The first and last ON/OFF then the second and 9th ON/OFF till they meet in the center. From center back to end right and left. There is also a POT to adjust speed of LEDs.
Anyway, thank you for your message. Kind regards. Mich