View Single Post
  #1   Spotlight this post!  
Unread 27-01-2012, 19:09
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Programming Light Sensor

Are you a rookie team or do you have last year's code you can base on? If you are totally new to programming, you probably need a programming mentor to guide you through it. What are you trying to do with the light sensors? That will affect how the code is written. Last year, we used the light sensors to follow the line. If you are not doing line following then last year's code may not be too useful. But you can still look at how to read the light sensor value. If you are talking about the same light sensor that was used last year, it is connected to a digital input channel. So you basically instantiate a DigitalInput object and call its Get() method to read the light sensor value (1 or 0). That's the basic operation of using the light sensor. Now how do you use the light sensor reading is a whole new story. Here is a simple example.
Code:
#define DIN_LIGHT_SENSOR    1    //Digital input channel 1
 
class MyRobot: public SimpleRobot
{
    //
    // This is to declare the light sensor object to be a digital input object.
    //
    DigitalInput lightSensor;
    DriverStationLCD *dsLCD;
 
    //
    // This initialize the light sensor object specifying the digital input channel.
    //
    MyRobot():
        lightSensor(DIN_LIGHT_SENSOR),
        dsLCD(DriverStationLCD::GetInstance())
    {
    }
 
    void OperatorControl()
    {
        while (IsEnabled() && IsOperatorControl())
        {
            UINT32 value = lightSensor.Get();
            dsLCD->PrintfLine(DriverStationLCD::kUserLine1, "value=%d", value);
            Wait(0.1);
        }
    }
};
If your light sensor is powered by a solenoid channel, then you need to add code to instantiate a solenoid object and "turn the power ON".
__________________
Reply With Quote