Question on Programming LED Indicators Using Robot C

Our team was having some trouble getting the LED Indicators to work using Robot C on our Cortex today.

According to the LED Robot C documentation, it should be as easy as using ‘turnLEDOn(sensorPort)’

In our case, we plugged the LED into Digital 4. After inserting ’ turnLEDOn(dgtl4); ’ into our teleoperated code, we received the following error -

Error:Undefined procedure ‘turnLEDOn’.

After searching around for a while, I found no topics on Vex Forum concerning this error. Has anyone else had this happen or used these LED’s in the past and ran into similar issues? I’m sure we’re just missing something obvious at this point.

Thanks in advance for the help.

Whenever I use the LEDs, I just use this, which seems to work:

SensorValue[dgtl4] = 0;

which should turn it on, and = 1 should turn it off. Note that we’re only using one equal sign to assign a value rather than check if it equates (which is ==).

Hopefully that helps, I dunno how clear I was when trying to explain.

You can just set the port to be a digital out. Then, SensorValue(LED) = 0 will turn it on and SensorValue(LED) = 1 will turn it off.

It appears that you’re looking at the documentation for Natural Language - this is not the setting that RobotC is set to by default. You CAN turn RobotC to Natural Language, but I wouldn’t recommend it if you’ve already been using normal RobotC.

Awesome, thanks guys. We’ll try these and report back our results.

Yes, these are natural language functions and are simply wrappers for SensorValue. This is the relevant code from the natural language header file for VEX (although they look backwards to me, ie. lenOn should be 0).

// enum for LED (on or off):
typedef enum
	ledOff	= 0,
	ledOn	= 1


//-------------------------------------------| TurnLEDON |--------------------------------------------

void turnLEDOn(tSensors digitalPort = dgtl2)
  SensorValue[digitalPort] = ledOn;


//-------------------------------------------| TurnLEDOFF |-------------------------------------------

void turnLEDOff(tSensors digitalPort = dgtl2)
  SensorValue[digitalPort] = ledOff;


This issue seems more complicated than it should be, so I’m back to ask the code vexperts a few more questions.

The robot currently has a 2-wire extension wire plugged into the correct red & black pin ports. This wire is plugged into digital 4, and the LED is plugged into the 2-wire extension. Whenever the robot is turned on, the LED immediately lights up.

Our limit switch is plugged into digital 5.

Code pertaining to this looks like the following:


#pragma config(Sensor, dgtl4,  conveyorLED,         sensorLEDtoVCC)
#pragma config(Sensor, dgtl5,  conveyorBumper,      sensorTouch)

Within Driver Control:

	  if(SensorValue[conveyorBumper] == (1))
	    SensorValue[conveyorLED] = 0;
	    SensorValue[conveyorLED] = 1;

We tried changing the sensor type from VEX LED to Digital Out as suggested, but we have the same results - LED is always on regardless of the limit switch being pressed.

Any ideas? Thanks again for the assistance.

As I recall, the LED is not plugged into the black and red wires, as they are just ground and +5V. The LED should be plugged into the black and white wires, which are ground and signal respectively.

Hmm, I plug them into signal and +5V (white and red), I don’t think the VEX leds can be plugged into black and white as they use two adjacent pins, I only have home brew ones so would need to check on that. When the signal goes low then led should light. There is a 1K series resistor (from what I remember) in the signal line to limit current. RobotC may invert the logic so you need to experiment.

I’m sorry, you’re right, it’s white and red. I haven’t used LEDs in a while. At more than $1 each, the’re not exactly something that every team has.

For debugging I just use regular 3mm leds, they work just as well.

You guys are great, moving the 2-wire connector did the trick. I should have read the LED specs a little more closely, but this is our first time trying to use them for driver feedback purposes. We’ll get a video up soon & will make sure to document this for anyone else that has issue with them in the future. Thanks again for the help!