View Single Post
  #2   Spotlight this post!  
Unread 17-02-2011, 20:24
speceottar's Avatar
speceottar speceottar is offline
Registered User
FRC #1504
 
Join Date: Jan 2010
Location: Michigan
Posts: 5
speceottar is an unknown quantity at this point
Re: Programming Light Sensor

The light sensor will return true if light is reflected back into it, and false if no light is reflected. In other words, when the light on it is green, it is false, and if the light is orange, it is a true. All you need is a simple if statement:

if(LightWhite->Get()) {
//the sensor is on the line
}

or

if(!LightWhite->Get()) {
//The sensor is not on the line
}

Depending on which sensors are on and which are off, you can find out where the robot is relative to the line, and move accordingly.

Another useful feature of c++ is that you have the ability to use booleans as ints (either a 1 or a 0) and add them together. The following would set "Lines" to the number of sensors that are triggered:
int Lines = WhiteLightOne->Get() + WhiteLightTwo->Get();
Reply With Quote