EasyManua.ls Logo

SunFounder 3in1 Kit - Page 144

Default Icon
351 pages
Print Icon
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...
SunFounder 3in1 Kit
Code
Note:
Open the 5.3.state_change_detection.ino file under the path of 3in1-kit\learning_project\5.3.
state_change_detection.
Or copy this code into Arduino IDE.
After the code is uploaded successfully, you press the button and the motor will turn; until you press the button again,
the motor will stop.
How it works?
1. Create variables and define pins for the motor and button.
...
int detectionState = 0;
int buttonState = 0;
int lastButtonState = 0;
detectionState is a flag whose value changes each time the button is pressed, e.g., 0 this time,
140 Chapter 4. Basic Projects

Related product manuals