0% found this document useful (0 votes)
30 views

Chapter 5 Challenges Questions

This document discusses using whiskers and digital input pins to detect contact and control a robot. It asks questions about whisker circuits and using if/else statements to call different navigation functions. Exercises provide code snippets to track whisker states with a single variable, modify behavior when both whiskers contact, add a pause function, and make the robot pause before moving. Projects propose modifying the code to make the robot beep on contact and navigate circles of different diameters based on which whisker is pressed.

Uploaded by

api-358351971
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Chapter 5 Challenges Questions

This document discusses using whiskers and digital input pins to detect contact and control a robot. It asks questions about whisker circuits and using if/else statements to call different navigation functions. Exercises provide code snippets to track whisker states with a single variable, modify behavior when both whiskers contact, add a pause function, and make the robot pause before moving. Projects propose modifying the code to make the robot beep on contact and navigate circles of different diameters based on which whisker is pressed.

Uploaded by

api-358351971
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 5 Challenges

Questions
1. What kind of electrical connection is a whisker?
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?
Zero (0) volts, resulting in binary zero (0) returned by digitalRead.

digitalRead(8) == 0 when whisker is pressed.

digitalRead(8) == 1 when whisker is not pressed.

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?

digitalRead(7)== 1 means the right whisker is not pressed.

digitalRead(7)== 0 means the right whisker is pressed.

digitalRead(5)== 1 means the left whisker is not pressed.

digitalRead(5)== 0 means the left whisker is pressed.

4. What statements did this chapter use to call different navigation


functions based on whisker states?
This chapter used if, ifelse, and ifelse ifelse statements to evaluate whisker
conditions and call navigation functions.

5. What is the purpose of having nested if statements?


If one condition turns out to be true, the code might need to evaluate another
condition with a nested if statement.

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.

2. Modify the loop function in RoamingWithWhiskers so that it makes the


BOE Shield-Bot stop and not restart when both whiskers contact at the same
time.

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.

3. Add a function named pause to RoamingWithWhiskers. It should make


the BOE Shield-Bot stay still for a certain amount of time.

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.

You might also like