}
//if changing-state of the button last beyond the time we set,we considered that
//the current button state is an effective change rather than a buffeting
if(millis() - lastChangeTime > captureTime){
//if button state is changed ,update the data.
if(reading != buttonState){
buttonState = reading;
//if the state is low ,the action is pressing
if(buttonState == LOW){
printf("Button is pressed!\n");
relayState = !relayState;
if(relayState){
printf("turn on relay ...\n");
}
else {
printf("turn off relay ...\n");
}
}
//if the state is high ,the action is releasing
else {
printf("Button is released!\n");
}
}
}
digitalWrite(relayPin,relayState);
lastbuttonState = reading;
}
return 0;
}