im using a potentiometers stored value in order to control the delay for the leds to turn on one by one with analogwrite (planning to make them turn on and off back and forth but i wanna try and get this fixed first)
but no matter what values i map for potval all the leds turn on in succession pretty much instantly
i cant tell if im just really stupid or not but i have no idea what the problem is
int leds[] = {3, 5, 6, 9, 10, 11};
int pot = A0;
int potVal;
int delayTime = potVal;
void setup()
{
for (int i = 0; i < 6; i++) {
pinMode(leds[i], OUTPUT);
}
pinMode(pot, INPUT);
}
void loop()
{
for (int l = 0; l < 6; l++) {
for (int i = 0; i < 256; i++) {
potVal = analogRead(pot);
potVal = map(potVal, 0, 1023, 100, 1000);
analogWrite(leds[l], i);
delay(delayTime);
}
}
}
Globally declared variables are set to 0 if no value is specified. The value of potVal will be 0. So when it is declared delayTime given a value of 0. The delayTime value will not follow the value of potVal, you must assign the value of potVal to delaytrime in the code (for loop).
The analogRead() function outputs 0 through 255, not 0 - 1000.