Vex Library and Sample Code

I’m not an experienced C programmer, but have enough programming experience to make significant changes to a working program or library. I’ve been using EasyC, and finally got MPLab working, with the EasyC library and also with the VexCode library.

Is there something in between – a simplified but open source library? For example, I want to make a fairly small change – the Arcade2() function in EasyC sets the RC to an arcade-style controller, and maps the controller to a motors in a particular direction. I need to dampen the output, and limit it, so that the extremes of the joystick are not 0 and 255 but rather 100 and 150. I can’t see where to modify the code to do this (obviously, I can’t modify the EasyC). I’ve poked around the VexCode c and can’t find where the RC is read, but even if I could, it appears that so much of the code is very low-level.

What I’m really looking for is a library (like the EasyC library, but with source code) that I can modify. Also, a set of high-level calls (reading a switch value, or setting a motor) using the VexCode, rather than EasyC, library would be helpful.

Right now, it appears that my choices are very high-level, limited functionality with EasyC, or low level bit manipulation, PWM and lots of hex values. Is there a way to say

   if (get_input(1) == 0) { // limit switch pressed
      set_motor(1, motor_speed);

without having to write get_input() and set_motor(), but with the ability to modify them?



well, gee, if you’re not going to read your inputs and check your outputs it doesn’t seem like there’s much left for you to do.

if you just want to hide implementation details you can always use defines. for instance…

#define LIMIT_SWITCH_PRESSED get_input(1) == 0

set_motor (1, motor_speed / 5 + 100);

which will damp your motor speed to values between 100 and 150. maybe another definition might help, e.g.

#define set_left (a) set_motor (1, (a) / 5 + 100)

so you get

if (LIMIT_SWITCH_PRESSED) set_left (motor_speed);

I’m hoping I’m missing something really obvious. I’ve looked though the ifi_*.c files, and the .h files, and everything is very low-level. I was using get_input(1) as an example, but I don’t believe there is a get_input function. Is there one? If so, where is it?

Is there sample code somewhere that turns two motors on and goes for 5 seconds, or reads a switch (or even better, the remote control unit)? Right now, it looks like if you want to simply go forward for 5 seconds, you have immerse yourself in hundreds of lines of code. Again, I keep hoping there’s some high-level function calls documented somewhere that I just can’t see (again, beside the ones in EasyC).


WPILib may be of some help to you, check it out here:

oops. sorry, thought you were maybe talking about some existing easyC code about which i know nothing.

to test for a limit switch closed on pin 1 in the analog/digital section of the rc and then send the damped signal from channel 1 of the radio to a motor connected to motor port 1 on the rc, use

if (rc_dig_in01 == 0)
pwm01 = pwm_in1 / 5 + 100;

the names used are all defined in ifi_aliases.h. the code would probably go into user_routines.c which runs every 18.5 ms.

Thanks – this is the type of library I’m looking for, and I’ve written to Brad asking about availability for Vex.

This is exactly what I’m looking for – thanks! Is there documentation on this anywhere, besides reading the source code comments? How does one know what rc_dig_in01, pwm01 and pwm_in1 are?

Or sample programs, simpler than the VexCode on Something like the GearToothTest that Brad has in WPILib, mentioned in the previous post?

Again, thanks very much, I feel like I’m at least getting closer to understanding how to program without EasyC.


arrrgh, you wouldn’t believe the long insightful answer i had for you when my connection timed out…

the short answer is study the sample code and refer to the 18f8520 datasheet, (watch any ad for a prescription med on the tele for a list of possible side effects), and have a look at, (a fine example of good intentions and what becomes of them).

anyway, to use pin 1 for input initialize ** io1 = 1** and to set it to output io1 = 0. when the rc powers up all pins are set to input so that you need not worry that the attached chainsaw on your deathbot will gobble your arm before you can jump clear.

must go to work…

Upgrading to EasyC 2.0 solved half my problem, as there is now a call GetRxInput(rx, channel) that gets the values I was looking for.

I think Brad Miller’s WPILib will solve some of the rest of the problems, but I’ll have to wait until that’s out to see.

Thanks for your reply.


i’m guessing that rx is receiver 1 or 2 and that channel is 1 through 6. since there’s no way to return an error indication, if we get rx 10, channel 9, we’ll just return the first channel from the first receiver.

unsigned char GetRXInput (unsigned char rx, unsigned char channel) {
  unsigned char bar;

  switch (rx * 6 + channel) {
    case 1 : bar = PWM_in1;  break;
    case 2 : bar = PWM_in2;  break;
    case 3 : bar = PWM_in3;  break;
    case 4 : bar = PWM_in4;  break;
    case 5 : bar = PWM_in5;  break;
    case 6 : bar = PWM_in6;  break;
    case 7 : bar = PWM_in7;  break;
    case 8 : bar = PWM_in8;  break;
    case 9 : bar = PWM_in9;  break;
    case 10 : bar = PWM_in10;  break;
    case 11 : bar = PWM_in11;  break;
    case 12 : bar = PWM_in12;  break;
  return bar;

don’t forget to include ifialiases.h.

I have tried writing the code in MPLab but have yielded disatsrous results. I have EasyC v.1 but lost my CD after unisntalling it :ahh: :confused: . Can anyone e-mail me the install file on the CD? I still have all of my other info such as installation key etc. but need the install file one the CD to reinstall it. e-mail me at Thanks - VEXguy365