08
The Crowtail-Hall Sensor uses the Allegro™ A1101 Hall-effect
switches are next-generation replacements for the popular
Allegro312x and 314x lines of unipolar switches. It measures the Hall
Effect, which is a production of a voltage difference across an
electrical conductor, transverse to an electric current in the conductor
as well as a magnetic field perpendicular to the current.
Lesson 3 – Hall speed test
Introduction
1. Macro definitions of PIR motion sensor pin, LED pin and buzzer pin.
2. Declare a variable to store the state of the collision sensor.
3. Setup led and buzzer as output.
4. Read the state of the collision sensor and store it to the variable collisionState.
5. If collision is detected(LOW), turn led and buzzer on for 0.5 seconds.
6. If a collision is not detected(HIGH), turn led and buzzer off.
Code overview
Code usage
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 collisionPin 3 #define ledPin 5 #define buzzerPin 6
It Causes the program to wait on this line of code for the amount of time in between brackets. After
the time has passed, the program will continue to the next line of code.
Delay: delay(500); delay(200);
The if / else statement allows your code to make corresponding choices for different results, running
a set of code when the logical statement in parentheses is true, and another set of code when the
logical statement is false. For the collision sensor, when the on-board switch of the collision sensor is
pressed, the state of the collision sensor is LOW which is different from most modules and it will be
HIGH when the on-board switch of collision sensor is not pressed.
If/else Statements: if(logic statement) {code to be run if the logic statement is true}
else {code to be run if the logic statement is false }
Содержание Crowtail Deluxe Kit
Страница 47: ......