Datasheet

Chapter 6 Light-Sensitive Navigation with Phototransistors
194Robotics with the BOE Shield-Bot
Your Turn: Test the Other Phototransistor Circuit
Before moving on to navigation, you’ll need to run the same test on the right (pin 6) light
sensor circuit. Both circuits have to be working well before you can move on to using them
for navigationthere’s that subsystem testing again!
In the
rcTime call, change the pin parameter from 8 to 6.
Change all instances of
tLeft to tRight.
Run the sketch, and verify that the pin 6 light sensor circuit is working.
It would also be nice to have a third sketch that tests both phototransistor
circuits.
Re-save the sketch as BothLightSensors, and update the comments.
Replace the
loop function with the one below.
Try rotating your BOE Shield-Bot until one side is pointing toward the brightest light source
in the room and the other is pointing away from it. What is the largest difference you can get
between
tLeft and tRight in the Serial Monitor?
void loop() // Main loop auto-repeats
{
long tLeft = rcTime(8); // Left rcTime -> tLeft
Serial.print("tLeft = "); // Display tLeft label
Serial.print(tLeft); // Display tLeft value
Serial.print(" us "); // Display tLeft units
long tRight = rcTime(6); // Left rcTime -> tRight
Serial.print("tRight = "); // Display tRight label
Serial.print(tRight); // Display tRight value
Serial.println(" us"); // Display tRight units + newline
delay(1000); // 1 second delay
}
rcTime and Voltage Decay
When light levels are low, the custom rcTime function might take time measurements too
large for
int or even word variables to store. The next step up in storage capacity is a long
variable, which can store values from -2,147,483,648 to 2,147,483,647. So, the function
definition
long rcTime(int pin) is set up to make the function return a long value when
it’s done. It also needs to know which pin to measure.
long rcTime(int pin)