![]() |
Programming Joystick Buttons to toggle a motor on and off
1 Attachment(s)
Hello there, can someone please help? I want to use a joystick button to toggle on and off a motor. If logitech button 3 is pressed once, turn the motor on with a speed of .5 If the button number 3 is pressed again, turn the motor off. In this case, it would be controlled by joystick connected to usb port 3.
Attached is what i have so far. Any help would be greatly appreciated. |
Re: Programming Joystick Buttons to toggle a motor on and off
Joystick stick3(3);//obviously
Jaguar jag1(3);//PWM port 3 bool btn3state=false; if (stick3.GetRawButton(3)) { if (btn3state) { jag3.Set(0.5); btn3state=false; } else { jag3.Set(0.0); btn3state=true; } } |
Re: Programming Joystick Buttons to toggle a motor on and off
One bug in your code, byteit101
Quote:
|
Re: Programming Joystick Buttons to toggle a motor on and off
no, it is in an if else
if it was Code:
if (btn3state) |
Re: Programming Joystick Buttons to toggle a motor on and off
This is how my team did it.
// this is all in our autonomous loop.... bool buttonUp = leftStick->GetRawButton(1); bool buttonDown = leftStick->GetRawButton(2); bool buttonStop= leftStick->GetRawButton(3); float elevatorSpeed; // this is the speed of our elevator if (buttonUP){ elevatorSpeed(1.0); } else if (buttonDown){ elevatorSpeed(-1.0); } else if (buttonStop){ elevatorSpeed(0.0); } ElevatorMotor1->Set(elevatorSpeed); // elevator motors one and two are ElevatorMotor2->Set(-elevatorSpeed);// on both sides of our elevator |
Re: Programming Joystick Buttons to toggle a motor on and off
Quote:
Code:
Joystick stick3(3);//obviouslyRemember, if that code is in a while loop, the variables should be declared *before* the loop. If the code is in a function, they should be static. |
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) |
| All times are GMT -5. The time now is 02:57. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi