I want to create a project, where there are 2 buttons as INPUT.
And one OUTPUT.
Where the input key disinni I named Input1 and input2.
One input serves as an on / off button, and input2 serves only as an off button with a specified time period when the OUTPUT is HIGH, then it will scroll to the LOW value.
Sketch that I created like this
Int input1 = 5; // the number of the input pin
Int input2 = 0;
Int output = 13; // the number of the output pin
Int state = LOW; // the current state of the output pin
Int reading; // the current reading from the input pin
Int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
Long time = 0; // the last time the output pin was toggled
Long debounce = 200; // the debounce time, increase if the output flickers
Unsigned long stoP = 4000;
Void setup ()
{
PinMode (input1, INPUT);
PinMode (output, OUTPUT);
PinMode (input2, INPUT);
}
Void loop () {
Reading = digitalRead (input1);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
If (reading == HIGH && previous == LOW && millis () - time> debounce)
{If (state == HIGH)
State = LOW;
Else
State = HIGH;
Time = millis ();}
DigitalWrite (output, state);
Previous = reading;
If (digitalRead (input2 == HIGH) && millis () - time> debounce + stoP)
{DigitalWrite (output, state = LOW);}
}
When i run it, for input1 can run as expected. But for input2, when I press briefly, (before the specified period, the output will immediately scroll to the LOW value.
Where is the error on my sketch writing.
Thanks for your advice and help.