Datasheet
Chapter 7 • Navigating with Infrared Headlights
248 • Robotics with the BOE Shield-Bot
if((irLeft == 0) || (irRight == 0))
{
for(int i = 0; i < 5; i++) // Repeat 5 times
{
digitalWrite(7, HIGH); // Turn indicator LEDs on
digitalWrite(8, HIGH);
tone(4, 4000, 10); // Sound alarm tone
delay(20); // 10 ms tone, 10 between tones
digitalWrite(7, LOW); // Turn indicator LEDs off
digitalWrite(8, LOW);
}
}
// Roam
irLeft = irDetect(9, 10, 38000); // Check for object on left
irRight = irDetect(2, 3, 38000); // Check for object on right
if((irLeft == 0) && (irRight == 0)) // If both sides detect
{
maneuver(-200, -200, 20); // Backward 20 milliseconds
}
else if(irLeft == 0) // If only left side detects
{
maneuver(200, -200, 20); // Right for 20 ms
}
else if(irRight == 0) // If only right side detects
{
maneuver(-200, 200, 20); // Left for 20 ms
}
else // Otherwise, no IR detects
{
maneuver(200, 200, 20); // Forward 20 ms
}
}