I’m using the Lynxmotion Wireless PS2 controller with an Atom Pro. I’ve been trying to figure out how to debounce the PS2 buttons. It looks like either the controller or the receiver buffer button presses, and I just want one press per button at a time. The buttons also repeat very quickly, which adds to the problem.
Here is what I came up with. It works great no matter how long you hold a button down and does not affect other button presses.
if Button_A and (ButtonBounces = 0) then
if Autonomous then
Autonomous = 0
serout S_OUT,i9600,"Remote control..",13]
else
Autonomous = 1
serout S_OUT,i9600,"Autonomous..",13]
endif
ButtonBounces = ButtonBounces + 1
else
if Button_A then
ButtonBounces = ButtonBounces + 1
else
ButtonBounces = 0
endif
endif
Looks good. So far I have not had any problems with the way the several programs up here deal with only processing a button once. That is they remember the previous button states and only process the button when that state changes.
IF (DualShock(1).bit3 = 0) and LastButton(0).bit3 THEN ;Start Button test
IF(RoverOn) THEN
;Turn Rover off
RoverOn = False
ELSE
;Turn Rover on
RoverOn = True
ENDIF
ENDIF
I don’t really get how I could apply this to what I am doing. I don’t understand what you are doing in your code.
Here is my latest code. No rocket science. I just replaced the counter with a bit variable.
[code] ’ Remote / Automomous Control Toggle
if Button_A and A_Enable then
if Autonomous then
Autonomous = 0
serout S_OUT,i9600,“Remote control…”,13]
else
Autonomous = 1
serout S_OUT,i9600,“Autonomous…”,13]
endif
A_Enable = FALSE
else
if Button_A then
A_Enable = FALSE
else
A_Enable = TRUE
endif
endif
[/code]
It works for me, and I understand what is going on, so will likely stay with it.