View Single Post
  #1   Spotlight this post!  
Unread 10-02-2005, 02:13
Fourevilmonkies's Avatar
Fourevilmonkies Fourevilmonkies is offline
Code monkey
#1369 (Minotaur)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Florida
Posts: 11
Fourevilmonkies is an unknown quantity at this point
Send a message via AIM to Fourevilmonkies Send a message via Yahoo to Fourevilmonkies
Unhappy One button wonder

If there is a thread about this please redirect me to it.

I have been fiddling around with this piece of code for quite a while (to me 1 week during build season is much too long). I have come up with an alternative but I found it way too messy for the drivers of the bot. Here is the unhappy code.

//somewhere at the top of user_routines.c
unsigned static int countify = 0;

//else where in the file
if (p1_sw_top == 1){
++countify;
if (countify % 2 == 0){
relay1_fwd = 1;
relay1_rev = 0;
}
if (countify % 2 != 0){
relay1_fwd = 0;
relay1_rev = 1;
}

What the above code is supposed to do is have the driver have to only hit the button once for it to do something then the driver hits it again for it to reset itself or do something else. Idealy we don't want the driver to have to tap the top switch on the joystick.

I only get a spaztastic numatic cylinder. I already know the cause is due to the fact that the value for p1_sw_top is read about every 26.2 ms so it goes through this code like a hot knife through butter. Is there a better way to do this?

The alternate code I am using is this

if ((p1_sw_top == 1) && (p1_sw_trig == 1)){
relay1_fwd = 1;
relay1_rev = 0;
}
if ((p1_sw_top == 1) && (p1_sw_trig == 0)){
relay1_fwd = 0;
relay1_rev = 1;
}

This makes it so I can have multiple buttons set up this way. This code does what its supposed to which is when someone hits the trigger then the button and something happens then they hit the button without the trigger and the inverse happens.
__________________
Come one guys, I just want to make you go pop.