View Single Post
  #2   Spotlight this post!  
Unread 18-02-2007, 03:33
Ari Allyn-Feuer Ari Allyn-Feuer is offline
Registered User
FRC #0753
 
Join Date: Feb 2006
Location: Bend, OR
Posts: 22
Ari Allyn-Feuer is on a distinguished road
Re: Need critique of programming idea and info!!!

Basically, the way you access the button inputs on the joysticks (not addressing switch breakout boxes and the like) is by using the button flags that the IFI default code uses (of course you can edit the #defines). The tags look like p1_sw_trig. There's p1, p2, p3, p4 (for the four joystick ports on the OI) and sw_trig (trigger), sw_top (thumb on the kit JSs), sw_aux1, sw_aux2.

The relay outputs have two parts, fwd and rev. For pistons, you always want rev to be 0, and forward is 1 if you want the piston forward and 0 if you want it to retract.

The way I turn a button into a toggle and use it to control a relay is like this. You make an unsigned char called "p3_sw_trig_old", and at the end of your routine put:

p3_sw_trig_old = p3_sw_trig;

so that the RC will remember how the button was last time. The times you want to switch the output is the very first loop they push the switch, and then to wait until they press it again. So you do something like:

if(p3_sw_top && !p3_sw_top_old) //If it's pressed but wasn't last loop.
{
relay_1_fwd = 1 - relay_1_fwd; //Toggle the relay's forward part.
relay_1_rev = 0;
}

I hope this helps. Post again with any more issues.

Ari.