I'm struggling to understand this bit of code.
it uses a potentiometer to set the LED blink speed but I don't fully understand it.
But I'm not sure how it uses the potentiometer value and the previous and current millis to set the blink speed.
Any help would be appreciated below is part of the code.
long PotentiometerValue1 = analogRead(Potentiometer1);
The value returned by analogRead will be an integer in the range 0...1023.
Does that make things clearer?
Have you looked at the basic blink without delay example?
long PotentiometerValue1 = analogRead(Potentiometer1); //read the pot
unsigned long currentMillis1 = millis(); //get the number of milliseconds since Arduino start or reboot
if (currentMillis1 - previousMillis1 >= PotentiometerValue1) //if the period since the last reading exceeds the pot reading
{
previousMillis1 = currentMillis1; //save the current value ready for mext time
if (ledState1 == LOW) //change the state of the LED
ledState1 = HIGH;
else
ledState1 = LOW;
The value returned by analogRead will be an integer in the range 0...1023.
Does that make things clearer?
Have you looked at the basic blink without delay example?
but how does it use the potentiometer after this to set the speed of the LED blink