Go to Post I don't really have a problem with school, as long as it doesn't get in the way of learning. - lukevanoort [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #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
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi