Documente Academic
Documente Profesional
Documente Cultură
Questions
1. What kind of electrical connection is a whisker?
A whisker is a normally open, momentary, single-pole, single-throw tactile switch.
2. When a whisker is pressed, what voltage occurs at the I/O pin
monitoring it? What binary value will the digitalRead function return? If
digital pin 8 is used to monitor the whisker circuit, what value
does digitalRead return when a whisker is pressed, and what value does it
return when a whisker is not pressed?
The voltage that occurs when the whisker is pressed is 0. The Binary value that the
digitalRead function return is zero. The value returned by the digitalRead function
when pressed is zero. When it is not being pressed the value returned is 1.
3. If digitalRead(7)== 1, what does that mean? What does it mean
if digitalRead(7)== 0? How about digitalRead(5)==
1 and digitalRead(5)== 0?
It means the right whisker is not being pressed. It means the right whisker is being
pressed. If the digitalRead is (5)==1, it means the left whisker is not being pressed.
It means the left whisker is being pressed
4. What statements did this chapter use to call different navigation
functions based on whisker states?
The statements used to call different navigation functions base on whisker states
are: if, if...else, and if...else if...else.
5. What is the purpose of having nested if statements?
The purpose is to use the code to evaluate another condition if one is found to be
true.
Exercises
1. Write a routine that uses a single variable named whiskers to track
whisker contacts. It should store a 3 when no whiskers are contacted, a 2 if
the right whisker is contacted, a 1 if the left whisker is contacted, or 0 if both
whiskers are contacted. Hint: multiply the result by two.
// Robotics with the BOE Shield Chapter 5, Exercise 1
// Value from 0 to 3 indicates whisker states:
// 0 = both, 1 = left, 2 = right, 3 = neither.
4. Modify the loop function so that the BOE Shield-Bot stays still for 0.5
seconds before backing up and turning.
void loop() // Main loop auto-repeats
{
byte wLeft = digitalRead(5); // Copy right result to wLeft
byte wRight = digitalRead(7); // Copy left result to wRight
int turn;
turn = 0;
if(wLeft == 0)
{
turn -= 10;
}
else if(wRight == 0)
{
turn += 10;
}