Datasheet
Light-Sensitive Navigation with Phototransistors • Chapter 6
Robotics with the BOE Shield-Bot • 203
int speedLeft, speedRight; // Declare speed variables
if (ndShade > 0.0) // Shade on right?
{ // Slow down left wheel
speedLeft = int(200.0 - (ndShade * 1000.0));
speedLeft = constrain(speedLeft, -200, 200);
speedRight = 200; // Full speed right wheel
}
This diagram shows an example of how this works when ndShade is 0.125. The left wheel
slows down because 200 – (0.125×1000) = 75. Since linear speed control is in the 100
to -100 range, it puts the wheel at about ¾ of full speed. Meanwhile, on the other
side,
speedRight is set to 200 for full speed forward.