View Single Post
  #7   Spotlight this post!  
Unread 25-01-2009, 17:47
WatersongX WatersongX is offline
Registered User
AKA: Matthew Keen
FRC #1111 (Powerhawks)
Team Role: Programmer
 
Join Date: Feb 2008
Rookie Year: 2006
Location: Edgewater, MD
Posts: 7
WatersongX is an unknown quantity at this point
Send a message via AIM to WatersongX
Re: Programming Joystick Buttons to toggle a motor on and off

May I reccomend a simpler system?

Assume the following variables:
Jaguar speedcontroller1
Joystick usb3
has been set up and initialized correctly
Code:
// with variable declarations (outside of main loop, so they don't reset every time)
bool togglestate = false;
bool lastu3b3state = false;

// somewhere in code (inside main loop, runs every time)
if ( lastu3b3state == true && usb3.GetRawButton( 3 ) == false ) togglestate = !togglestate;
speedcontroller1.Set( togglestate?0.5f:0.0f );

// at the end of the main loop, or at least after the button is done being used
lastu3b3state = usb3.GetRawButton( 3 );
Reply With Quote