int LEDPin = 9; // declare LEDPin to arduino pin
int potPin = A0; // declare potentiometer pin (potPin) analog pin A0
int readValue; // variable to read potentiometer
float blinkRate; // declare blinkRate variable
unsigned long previousMillis = 0; // store the last timestamp (assign 0 for now)
void setup() {
Serial.begin(9600); // turn on serial port
pinMode(potPin, INPUT); // set potPin to be an input
pinMode(LEDPin, OUTPUT); // set LEDPin to an output
}
void loop() {
unsigned long currentMillis = millis(); // get current timestamp
readValue = analogRead(potPin); // read potentiometer value and assign to readValue
blinkRate = (-0.9 / 1023.0 * readValue + 1) * 1000; // calculate blinkRate and convert to milliseconds
Serial.println(currentMillis - previousMillis);
if (currentMillis - previousMillis >= blinkRate) {
previousMillis = currentMillis; // save last time LED was toggled
digitalWrite(LEDPin, !digitalRead(LEDPin)); //toggle the LED without delay
}
// Serial.print("blinkRate: ");
// Serial.println(blinkRate);
}