Chapter 5 Challenges Questions
Chapter 5 Challenges Questions
Questions
1. What kind of electrical connection is a whisker?
A normally open, momentary, single-pole, single-throw tactile switch.
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.
Since digitalRead returns 1 or 0, your code can multiply digitalRead(5) by 2 and
store the result in the whiskers variable. It can then add the result of
digitalRead(7) to the whiskers variable and the result will be 3 for no whiskers.
In the if((wLeft == 0) && (wRight == 0)) block, remove the backward and
turnLeft function and replace them with calls to servoLeft.detach and
servoRight.detach.
4. Modify the loop function so that the BOE Shield-Bot stays still for 0.5
seconds before backing up and turning.
Projects
1. Modify RoamingWithWhiskers so that the BOE Shield-Bot stops and
makes a 4 kHz beep that lasts 100 ms before executing its usual evasive
maneuver. Make it beep twice if both whisker contacts are detected during
the same sample. HINT: Use the pause function you developed in the
Exercises section to make it pause immediately after the tone starts playing.
Also, a 0.2 second pause after the tone call separates the 0.1 second tone
from servo motion, or allows you to hear a second tone.
2. Modify RoamingWithWhiskers so that the BOE Shield-Bot roams in a 1
yard (or 1 meter) diameter circle. When you touch one whisker, it will cause
the BOE Shield-Bot to travel in a tighter circle (smaller diameter). When you
touch the other whisker, it will cause the BOE Shield-Bot to navigate in a
wider diameter circle.