Hello,
As the input state changes in the state change detection example the led is turned on/off .
Following is my code
int buttonInput = 2;
int led = 13;
int lastButtonState = 0;
int buttonState = 0;
int buttonPushCounter = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonInput,INPUT_PULLUP);
pinMode(led,OUTPUT);
}
void loop() {
buttonState=digitalRead(buttonInput);
button();
}
void button()
{
if(buttonState !=lastButtonState )
{
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
unsigned long currentMillis = millis();
while(millis()< currentMillis + 20000)
{
Serial.println("Inside While");
if(buttonPushCounter>1)
{
digitalWrite(led,HIGH);
Serial.println("on");
buttonPushCounter = 0;
}
}
} else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
digitalWrite(led,LOW);
}
// Delay a little bit to avoid bouncing
delay(50);
}
lastButtonState = buttonState;
}
i want to "on" the led on second count and that should be done in certain period of time, as the code works when buttonPushCounter=1 and it goes in while loop for 20sec but it doesn't detect the second buttonPushCounter , and after 20sec it exits the while loop i want to detect the buttonPushCounter in the given 20sec time