Hello,
I'm fairly new to Arduino, I have a question on how can you instruct the Arduino that if a push button isn't pressed for an amount of time it'll reset a process or output. Here's a simple code, I'm counting up to 10 and it should light up another led when it reaches 10, but if it doesn't reach 10 for an amount of time, or no button press is made in that amount of time it'll go back to it's original state.
int startbtn = 5;
int startled = 13;
int stopled = 12;
int defaultState = 0;
int count = 0;
void setup() {
pinMode(5, INPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(stopled, HIGH);
int buttonState = digitalRead(2);
if (buttonState != defaultState) {
if (buttonState == HIGH) {
count++;
delay(250);
Serial.println(count);
if (count == 10) {
digitalWrite(startled, HIGH);
digitalWrite(stopled, LOW);
}
}
}
}
Now, I want to revert back to the original state if the counter doesn't reach 10 for a specific time and reset the process to it's initial state like stopled will be HIGH again and counter will return to zero again.
Any help is accepted, thank you