the LightPointer program

The LightPointer program presented next demonstrates how to use variables to remember values that you want to use later in your program. This program uses the Color or Light Sensor to point the TriBot at a light source by spinning the robot in a circle and remembering where the sensor detected the brightest light. The code you develop here could be used as part of a larger program, such as a fire-fighting simulation or a robot that tracks the position of the sun to adjust a solar panel.

In the following text and images, I’ll use the Color Sensor (in Light Sensor mode) to read the level of ambient light. The program also works just as well with the Light Sensor. The sensor can be placed either at the front of the TriBot ...

Get The Art of LEGO MINDSTORMS NXT-G Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.