Hi, I have a code to blink one LED. I am trying to get one Potentiometer to set the on time of the blink and the other potentiometer to set the off time of the blink using millis and no delays.
Can someone please help me with this?
Thanks.
Adam.
//Using Millis with 2 Pots to Blink LED on time with one pot and LED off time with the other Pot.
int Pot = A0; //Led On Time Pot.
int Pot2 = A1; //Led Off Time Pot.
int PotRead;
int PotRead2;
int LedPin = 13;
int LedState;
unsigned long PreviousTime = 0;
unsigned long PreviousTime2 = 0;
void setup() {
pinMode (LedPin, OUTPUT);
pinMode (Pot, INPUT);
pinMode (Pot2, INPUT);
digitalWrite (LedPin, HIGH);
}
void loop() {
PotRead = analogRead (Pot); //Led On Time Pot.
PotRead2 = analogRead (Pot2); //Led Off Time Pot.
unsigned long Time = millis();
unsigned long Time2 = millis();
// Turn on LED Time.
if ( LedState == LOW && Time - PreviousTime >= PotRead) {
PreviousTime = Time;
LedState = HIGH;
}
//Turn off LED Time.
if (LedState == HIGH && Time2 - PreviousTime2 >= PotRead2) {
PreviousTime2 = Time2;
LedState = LOW;
}
digitalWrite (LedPin, LedState);
}