Datasheet
Light-Sensitive Navigation with Phototransistors • Chapter 6
Robotics with the BOE Shield-Bot • 213
float volts(int adPin) // Measures volts at adPin
{ // Returns floating point voltage
return float(analogRead(adPin)) * 5.0 / 1024.0;
}
2. The solution for this one is to make a copy of LightSeekingShieldBot, and add one
command to the
loop function: ndShade = -ndShade. Add it right before the
if…else statement. Then, instead of indicating shade to turn away from, it
indicates bright light to turn away from. Another approach would be to use
an
ndLight calculation that equals tLeft / (tLeft + tRight). You would
have to search/replace
ndShade with ndLight in the sketch.
Use LightSensorValues to determine a threshold. It’s best to take
tLeft +
tRight
. You can use the LightSensorValues to test this. Start with a value that’s
1/4 of the way from reaching the bright light level. So if
tLeft + tRight = 4000
and 400 for bright light, use the value 400 + ¼ × (4000 – 400) = 400 + 900 =
1300. Don’t just use 1300, it’s just an example; figure out the value for your
conditions.
Next, add an
if statement similar to the one from HaltUnderBrightLight to the
main
loop of LightSeekingShieldBot. Careful though, HaltUnderBrightLight uses
the greater than (
>) operator because it’s using a voltage output circuit. We need
the less than (
<) operator for the QT circuit because smaller values mean brighter
light. We also need to express the threshold as a floating point value, like 1300.0.
Here’s an example:
// Add this if condition to stop under the bright lamp.
if((tRight + tLeft) < 1300.0) // tLeft+tRight < 1300?
{
servoLeft.detach(); // Stop servo signals
servoRight.detach();
}
3. Here’s a modified version of LightSeekingShieldBot that will do the trick.
Remember, you’ll still have to calibrate it to your lighting conditions.
/*
* Robotics with the BOE Shield - Chapter 6, Project 3
* Roams toward light and away from shade.
*/