11
STEP1:
Plug the Crowtail-Base Shield onto the Arduino or Crowduino Board.
Hardware Connection
STEP2:
Connect Crowtail-LED to
Crowtail-Base shield’s D4 and Crowtail-PIR
motion sensor to D5 port. The complete
connection is as follows:
Open the
P04_Intelligent_corridor_light
with
Arduino IDE and upload it.
When you wave or walk within the range of the PIR motion sensor, the LED will turn on for 5 seconds.
If there is no movement of the object within the sensing range of the PIR motion sensor, the LED will
not light up.
What will you see
1. Macro definitions of PIR motion sensor pin and LED pin.
2. Define whether the module is output or input.
3. Create functions to turn LED on and turn LED off separately.
4. Create a boolean type object motion detection function that returns true when the object
moves, otherwise return false.
5. Determine the value returned by the object motion detection function in the loop() function to call
turnOnLED() and turnOffLED functions to turn the LED on or off.
6. Repeat loop() function.
Code overview
The prototype of the macro definition constant is #define [MacroName] [MacroValue]. What is the
difference between a macro definition constant and a variable? First, Macro-defined constants
cannot be changed while the program is running. Variables can be changed. Second, the variable
can be used inside the function defined by it, but the life cycle end when the function ends. The
macro defines the constant until the entire program runs, the life cycle ends.
Macro definition: #define LED 4 #define PIR_MOTION_SENSOR 5
Objects created with boolean types (including variables and methods) have only two values: true and
Boolean type: boolean isPeopleDetected(){}
Code usage
Содержание Crowtail
Страница 48: ......