Pointers in EasyC

Can EasyC deal with pointers? I know the camera capture command uses them (but I don’t know why), but I haven’t found a way to implement them myself.

I do remember getting an error message when I tried that seemed to indicate it was possible. I had tried to do something like:

PWM_1_value = &PWM01

(though I probably have the syntax and names wrong here) and when it gave me a dialog box saying something like “You tried to use a pointer without initializing it.” When I try to initialize *PWM01 as a variable, it won’t let me, of course (“invalid variable name,” or some such).

P.S.: “PWM01” is a guess at what name I tried to use. I don’t remember what it’s actually called, but I think I somehow knew when I tried that.

You can declare pointer variables by putting ‘User code’ blocks at the beginning of your function. For example, the following code declares two variables and makes the pointer variable point at the value variable and sets the value to 4.

unsigned char *pointer;
unsigned char value;

pointer = &value;
*pointer = 4;

Beautiful! Thanks.

Now does anyone know what names to use to point to say, a certain PWM or relay value?

Why don’t you just assign a variable to the PWM Control block?

PWM_01 = 160;

SetPWM ( 1 , PWM_01 ) ;

You can do the same with a relay.

Relay_1_FWD = 1;

SetRelay ( 1 , Relay_1_FWD , Relay_1_REV ) ;

Is that what your trying to do?



Hmm… why didn’t I think of that?

That would be a workable work-around (redundant?), though it would be kinda tedious to use two blocks each time I set a PWM.

What I’m actually trying to do is set up the OI LEDs to show PWM, relay, and switch values, like they do with the default code, but with EasyC. It’s sounding like there’s no way to point to PWM values, like in “hard” C, but then how does the camera do it for pan and tilt?

Anyway, it’s not really critical; maybe I’ll just have the LEDs blink in pretty patterns for the sake of my easily amused teammates. (Yeah, I guess that includes me.)

Can you explain in more detail what you are trying to do? Are you trying to make
an LED go active when the camera locks on?

Well, sort of. I want to show how far left or right or up or down the camera is pointing (relative to the bot) using multiple OI LEDs per axis. (Something along the lines of an LED for “too far left,” an LED for “locked on,” and an LED for “too far right.”) That way we can manually turn the bot to point at the goal by centering the pan, and tell if our shooter’s in range by the tilt angle.

I thought I knew how to do it using the capture command’s pan and tilt outputs, but when I tried, it didn’t seem to work, and I don’t know enough about the camera and EasyC’s camera commands to tell why.

Do the servos have to be plugged into the camera board to get those values? Does servo tracking have to be enabled? Why are the camera’s outputs pointers? And if the camera can get servo outputs from the controller (as opposed to the camera board), how can I?

That last I originally wanted to know in order to emulate what the default code does with the LEDs. Then I learned that the default code’s LEDs just show the OI inputs, so it’s mainly just a curiosity now.

Is that enough info, or way too much?:slight_smile:

Edit: No longer just a curiosity, as I found out the “hard” c camera code reads PWM output values, and I will probably need to to make our EasyC camera code work. How does “hard” c do it?