Using Potentiometer to Control LED Blink Speed

Try reading the actual value of potentiometer in a loop. Something like this:

int potpin = 0;  
int ledpin = 13;
int val;    
int lastChange; // the time of changing pin state

void setup()
{
  pinMode(ledpin, OUTPUT);
  val = map(analogRead(potpin), 0, 1023, 500, 5);  // actual value
}

void loop()
{
  digitalWrite(ledpin, HIGH);
  lastChange = millis();  // ledpin state changed NOW
  while(lastChange + val <= millis())  // loop while there's time for it :)
  {
    val = map(analogRead(potpin), 0, 1023, 500, 5);  // read the value every time
  }

  // the same here:
  digitalWrite(ledpin, LOW);
  lastChange = millis();
  while(lastChange + val <= millis())
  {
    val = map(analogRead(potpin), 0, 1023, 500, 5);  
  }
}

I didn't check it, I don't have the access to IDE right now, but maybe it will work :slight_smile: