A Complete Beginners Guide to the Arduino

Can someone help me with the code for Lesson 6, Interactive LED Chase Effect exercise 2. I have ten (10) LED’s set up for a “Chase Effect” However for an extra excercise Mike suggested to try for a “Bouncing Ball” effect. Basically to Start at element 0 go to element 9 and then reverse but only going back as far as element 1 and increasing it for a bouncing ball effect. I have been trying to solve this puzzle for a week.
Thanks,
RFA

Can we take a look at your code?

First thing that came to my mind:

//PSEUDOCODE
all leds off
for 1 to NUM_OF_LEDS store the current iteration in i and do
  for all leds starting at i-1 do
    turn on 
    wait
    turn off
    wait
    increase index
  start at end and iterate over all leds until current iteration is equal to i
    turn on
    wait
    turn off
    wait
    decrease index

Obfuscated pseudo code :sunglasses:

//Project 5 - LED Chase Effect
// Create array for LED pins
byte ledPin = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int ledDelay (100); // delay between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
int potPin = 2;
int height = 0;

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

void loop() {
// Read the value from the pot
ledDelay = analogRead (potPin);
// If it has been ledDelay ms since last chane
if ((millis() - changeTime)> ledDelay)
{
changeLED();
changeTime = millis();
}
}

void changeLED() {
// turn off all LED’s
for (int x=0; x<10; x++){
digitalWrite(ledPin, 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 ==height) {direction =1;}
if (currentLED == height) {height += 1;}
}