how I stop ( readMechine)counter after 10sec or may earlier say 5 sec. if no input .
Thanks
int machinePin = 3; // input pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
int readMechine=0; //number of times microsw was pressed
int ledPin=13; // visual light
int audioPin = 12; // buzzer
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(machinePin, INPUT);
pinMode(ledPin,OUTPUT);
pinMode(audioPin, OUTPUT);
}
void loop()
{
reading = digitalRead(machinePin);
if (reading == HIGH && previous == LOW && millis() - time > debounce)
{
//increment count
readMechine++;
// ... and remember when the last button press was
time = millis();
}
previous = reading;
if (readMechine==3)
{
digitalWrite(ledPin,HIGH);
}
if (readMechine==5)
{
digitalWrite(audioPin,HIGH);
readMechine=0; //reset count
}
}