i'm using the blink without delay to try and code a potentiometer to vary the speed of the blink:
int ledPin = 13;
int value = LOW;
long nextTime = 0;
long interval = 1000;
int offset(int duration) {
int newDuration;
int rate = analogRead(0);
newDuration = ((rate+512)/1023)*duration;
return (int)newDuration;
}
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (millis() > nextTime) {
nextTime = millis() + offset(interval);
if (value == LOW)
value = HIGH;
else
value = LOW;
digitalWrite(ledPin, value);
}
}
when it is going really fast, and you change the potentiometer to get a slower rate it works fine, but when it is going slow, the speed doesn't change immediately because i have to wait for the next frame to come and then the speed gets updated. is there a way to avoid this?
thanks