Datasheet

Chapter 5 Tactile Navigation with Whiskers
174Robotics with the BOE Shield-Bot
void backward(int time) // Backward function
{
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}
2. Start with the Circle sketch, from the Chapter 4 Project Solutions that begin on
page 144. Comment the
detach calls and move the circle code to the loop
function and reduce the delay to 50 ms so that it can check the whiskers for
contacts 20 times per second. Then, add the whisker monitoring code with an
if
statement that reduces or increases a variable that slows the right wheel when
the right whisker is pressed, or speeds up the right wheel if the left whisker is
pressed.
// Robotics with the BOE Shield - Chapter 5, project 2 WhiskerCircle
// BOE Shield-Bot navigates a circle of 1 yard diameter.
// Tightens turn if right whisker pressed; reduces turn if left whisker
// is pressed.
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servos
Servo servoRight;
int turn;
void setup() // Built-in initialization block
{
pinMode(7, INPUT); // Set right whisker pin to input
pinMode(5, INPUT); // Set left whisker pin to input
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone
servoLeft.attach(13); // Attach left signal to Port 13
servoRight.attach(12); // Attach right signal to Port 12
turn = 0;
// servoLeft.detach(); // Stop sending servo signals
// servoRight.detach();
}