Output is always HIGH ,except if input goes from HIGH to LOW, and within 2 seconds goes HIGH again.
If time is more than 2 seconds, output remains HIGH, and in every other case, just need to be low if input is HIGH within 2 seconds after switching from HIGH to LOW.
Am I right in assuming that you havenāt written any code at all, and expect someone here to solve your problem? This sounds like a classroom example, so getting a solution here would not really be helping you at all. As already suggested, you should try to solve it yourself and then post your program once you get stuck and someone will surely assist.
If you are really stuck, copy the āblink.inoā sketch as a starting point and modify it to blink when your input goes HIGH. Once you have that working, expand the program and add the additional logic.
I maked it this way but something is wrong :shock:
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
static unsigned long timer = 0;
unsigned long interval = 2000;
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState)
{
if (buttonState == LOW && lastButtonState == HIGH)
{
timer = millis();
if (millis() - timer <= interval )
if (buttonState == HIGH && lastButtonState== LOW)
{
digitalWrite(ledPin, LOW);
}
}
else
{
digitalWrite(ledPin, HIGH);
}
}
lastButtonState = buttonState;
}