EasyManua.ls Logo

Freenove Ultimate Starter Kit - Page 68

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 2 Button & LED
68
www.freenove.com ā–ˆ
ā–ˆ support@freenove.com
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");
}

Table of Contents