I'm trying to activate vex flashlights with a light sensor and can't seem to get the code

#1

Here is my code,
Taskmain()
{
While(true)
{
If(SensorValue[in1]<50)
{
Motor[port1]=127;
Motor[port10]=127;
}
}
}

Ports 1 and 10 are flashlights and in1 is the light sensor

0 Likes

#2

Maybe this is just a formatting thing, but there should be a space between “task” and “main”.

In the future, indent all your code with four spaces when posting it on the forum and it will be formatted more properly.

EDIT: and I’m not sure about some of those capitalizations either, maybe ROBOTC will be unhappy with some of the capitalized keywords. If you can post details about any errors you’re getting, that can help us to debug your program.

1 Like

#3

Assuming you are using the line follower sensors

#pragma config(Sensor, anlg0,  LightSensor,     sensorReflection)
Task main()
{
     while(true)
      {
         If(SensorValue[LightSensor]<50)
         {
                Motor[port1]=127;
                Motor[port10]=127;
          }
    }
}
1 Like