I am curious whether I can add a button to reset the value of the potentiometer.
I set up a potentiometer to control the light level of the LED. On the other hand, I added another button to turn the LED to switch on and off the light. I tried many times. However, it seems the value keeps referring to the potentiometer. May I ask whether anyone knows how I can fix it? Thank you.
My code is like this:
//For dimmable orange bulb
int Potent = 0;
int pwm = 0;
//For Master Button
int buttonStateAll = 0;
int stateAll = 0;
int sensorValue;
void setup()
{
pinMode(10, OUTPUT);
pinMode(4, INPUT);
pinMode(A0, INPUT);
Serial.begin(9600);
}
void loop()
{
//Control the dimmable LED
Potent = analogRead(A0);
pwm = map(Potent, 0, 1023, 0, 255);
analogWrite(10, pwm);
//Master Control
buttonStateAll = digitalRead(4);
if (digitalRead(4) == HIGH)
{
if (stateAll == 0)
{
analogWrite(10, 0);
stateAll += 1;
}
else
{
analogWrite(10, 255);
stateAll = 0;
}
}
}