View Single Post
  #6   Spotlight this post!  
Unread 10-02-2005, 09:43
zarf's Avatar
zarf zarf is offline
Only C Programming Mentor on Team
AKA: Joseph Pride
#0500 (Coast Guard Raptors)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Connecticut
Posts: 3
zarf is an unknown quantity at this point
Send a message via AIM to zarf
Re: One button wonder

Here's what seems to be the problem, at least to me. You're doing this on your slow loop, every time, right? Because it seems to me that, with the if statement how it is, it will re-analyze every time it goes through the slow loop, and keep turning the value "on" and "off" until you let go of the joystick button. This makes it basically random, which value it's going to end up with when you let go. I think in most cases, the slow loop still runs faster than a player can reasonably press and release the joystick button.

So. You want to activate this routine only when you have _just_ turned on the button, and not again and again as long as you have the button held.

Better would be to define a global variable unsigned char ButtonON = 0; and then check to see if the button was already on during the last loop before you act on it. So inside your slow loop, here's what you would do:

unsigned char Countify = 0;

if (p1_sw_top == 1 && ButtonON = 0){
ButtonOn = 1;
if (relay1_fwd == 0 || relay1_rev == 1){
relay1_fwd = 1;
relay1_rev = 0;
}
else{
relay1_fwd = 0;
relay1_rev = 1;
}
}
else if (ButtonON == 1 && p1_sw_top == 0)
ButtonON = 0;

This means, that if your button was on the last time you came through the slow loop and it's still on now, it doesn't count as another press of the button.

Good luck!
--Zarf