EasyManua.ls Logo

Freenove Ultimate Starter Kit

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...
157
Chapter 14 Relay & Motor
ā–ˆ www.freenove.com
support@freenove.com ā–ˆ
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
}
//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;
}
The code is in the same logic as TableLamp code above.

Table of Contents