Datasheet

Tactile Navigation with Whiskers • Chapter 5
Robotics with the BOE Shield-Bot 153
Serial.begin(9600); // Set data rate to 9600 bps
}
void loop() // Main loop auto-repeats
{
byte wLeft = digitalRead(5); // Copy left result to wLeft
byte wRight = digitalRead(7); // Copy right result to wRight
Serial.print(wLeft); // Display left whisker state
Serial.println(wRight); // Display right whisker state
delay(50); // Pause for 50 ms
}
Look at the values displayed in the Serial Monitor. With no whiskers pressed, it
should display 11, indicating 5 V is applied to both digital inputs (5 and 7).
Press the right whisker into its three-pin header, and note the values displayed in
the Serial Monitor. It should now read 10.
Release the right whisker and press the left whisker into its three-pin header, and
note the value displayed in the Serial Monitor again. This time it should read 01.
Press both whiskers against both three-pin headers. Now it should read 00.
If the whiskers passed all these tests, you’re ready to move on. If not, check your
sketch and circuits for errors.
These steps are important! Seriously, you’ve got to make sure your circuit and code pass these
tests before continuing. The rest of the examples in this chapter rely on the whiskers working
correctly. If you haven’t tested and corrected any errors, the rest of the examples won’t work.
How DisplayWhiskerStates Works
In the setup function, pinMode(7, INPUT) and pinMode(5, INPUT) set digital pins 7
and 5 to input so they can monitor the voltages applied by the whisker circuits.
pinMode(7, INPUT); // Set right whisker pin to input
pinMode(5, INPUT); // Set left whisker pin to input
In the loop function, each call to digitalRead returns a 0 if the whisker is pressed or 1 if it
is not. Those values get copied to variables named
wLeft and wRight, which are short for
whisker-left and whisker-right.
byte wLeft = digitalRead(5); // Copy left result to wLeft
byte wRight = digitalRead(7); // Copy right result to wRight