Lynxmotion Tech Support

www.lynxmotion.com
It is currently Tue May 21, 2013 9:27 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Jun 06, 2010 7:14 pm 
Offline
Robot Guru
User avatar

Joined: Sun Aug 27, 2006 11:26 pm
Posts: 2757
Location: Directly above the center of the Earth
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.
Code:
   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


I also have:
Code:
ButtonBounces var word
ButtonBounces = 0

8-Dale

_________________
I can usually handle complexity. It's the simple things that always confound me..
Open your mind, Read, Learn, Think, Apply..


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 8:32 am 
Offline
Robot Guru
User avatar

Joined: Sat Apr 15, 2006 1:42 pm
Posts: 4414
Hi Dale,

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.
Code:
 ...
   shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
   DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
   high PS2SEL
   pause 10   
 
   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
...
     LastButton(0) = DualShock(1)
     LastButton(1) = DualShock(2)
RETURN


Kurt


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 9:24 am 
Offline
Robot Guru
User avatar

Joined: Sun Aug 27, 2006 11:26 pm
Posts: 2757
Location: Directly above the center of the Earth
I believe my code can be simplified a bit, and I want to get rid of the counter.

8-Dale

_________________
I can usually handle complexity. It's the simple things that always confound me..
Open your mind, Read, Learn, Think, Apply..


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 10:46 am 
Offline
Robot Guru
User avatar

Joined: Sun Aug 27, 2006 11:26 pm
Posts: 2757
Location: Directly above the center of the Earth
kurte wrote:
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.
Code:
 ...
   shiftin PS2DAT,PS2CLK,FASTLSBPOST,[DualShock(0)\8, DualShock(1)\8, DualShock(2)\8, DualShock(3)\8, |
   DualShock(4)\8, DualShock(5)\8, DualShock(6)\8]
   high PS2SEL
   pause 10   
 
   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
...
     LastButton(0) = DualShock(1)
     LastButton(1) = DualShock(2)
RETURN

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

It works for me, and I understand what is going on, so will likely stay with it.

8-Dale

_________________
I can usually handle complexity. It's the simple things that always confound me..
Open your mind, Read, Learn, Think, Apply..


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group