Beruflich Dokumente
Kultur Dokumente
Chapter 7 Challenges
Questions
1. What is the frequency of the
signal sent by tone(9, 38000, 8)?
How long does this call send the
signal for? What I/O pin does the
IR LED circuit have to be
connected to in order to broadcast
this signal?
Exercises
1. Modify a line of code in
IrInterferenceSniffer so that it only
monitors one of the IR detectors.
Remove the left IR detector from the
code. Comment out int irLeft =
digitalRead(10) by placing // to its left.
Then, change if((irLeft == 0) || (irRight
== 0)) to if(irRight == 0).
1. Modify AvoidTableEdge so
that when it makes the BOE
Shield-Bot back up, it also turns a
little so that it doesnt get stuck
going straight back at the same
drop-off.
Linear wheel speed control is in the
-100 to 100 range. So -75 should be a
little slower than full speed backward.
With that in mind, try changing
maneuver(-200, -200, 250) to
maneuver(-75, -200, 250).
Projects
1. Design a BOE Shield-Bot
application that sits still until you
wave your hand in front of it, then
it starts roaming.
Add this code at the end of the setup
function in FastIrRoaming:
int irLeft = 1; //
int irRight = 1; //
initialize both to 1
{
irLeft = irDetect(9, 10, 38000); //
int irRight = 1; //
initialize both to 1
output
tone(4, 3000, 1000); //
delay(1000); //
servoLeft.attach(13); //
servoRight.attach(12); //
}
void loop() //
// Sniff
{
for(int i = 0; i < 5; i++) //
Repeat 5 times
digitalWrite(7, HIGH); //
digitalWrite(8, HIGH);
delay(20); // 10 ms
digitalWrite(7, LOW); //
// Roam
// Backward 20 milliseconds
else if(irLeft == 0) // If
// Right for 20 ms
}
else if(irRight == 0) //
// Left for 20 ms
else //
Otherwise, no IR detects
// Forward 20 ms
}
}