if(millis() - lastChangeTime > captureTime){
//if button state is changed ,update the data.
if(reading != buttonState){
buttonState = reading;
Finally, judge the state of Button. And if it is low level, the changing state indicates that the button is pressed,
if the state is high level, then the button is released. Here, we change the status of the LED variable, and then
update the state of LED.
if(buttonState == LOW){
printf("Button is pressed!\n");
ledState = !ledState;
if(ledState){
printf("turn on LED ...\n");
}
else {
printf("turn off LED ...\n");
}
}
//if the state is high ,the action is releasing
else {
printf("Button is released!\n");
}