Professional Documents
Culture Documents
Chapter 5 Challenges Questions
Chapter 5 Challenges Questions
Questions
1. What kind of electrical connection is a whisker?
A 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 volts, resulting in binary zero (0) returned by digitalRead.
digitalRead(8) == 0 when whisker is pressed.
digitalRead(8) == 1 when whisker is not pressed.
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;
}