Hello, I have an LED "rail" that lights each LED from left to right, then right to left, continuously. I'm trying to control the speed of the delay with a potentiometer. With the code I currently have, it seems like it "should" just count the potentiometer value, then plug that number into delay. But it doesn't seem to work. It just switches LED state about every half a second or so, which seems like an arbitrary delay value which I can't determine where it's coming from.
Here is my code:
int ledPins[]={2,3,4,5,6,7,8,9,10};
int potSpeed = 0;
int potPin = A0;
void setup(){
//Serial.begin(9600);
for (int i =0; i <9; i++)
{
pinMode(ledPins[i],OUTPUT);
}
pinMode(potPin, INPUT);
}
void loop(){
int potValue = analogRead(potPin);
/*
Serial.print("Pot Value: ");
Serial.print(potValue);
Serial.println("");
*/
potSpeed = potValue;
int i = 0;
while (i<8)
{
{
digitalWrite(ledPins[i],HIGH);
delay(potSpeed);
digitalWrite(ledPins[i],LOW);
i++;
}
}
i = 8;
while (i >0)
{
digitalWrite(ledPins[i],HIGH);
delay(potSpeed);
digitalWrite(ledPins[i],LOW);
i--;
}
}