Re: Need serious help with coding!!
Quote:
Originally Posted by kinganu123
(Post 1146195)
a basic code would be
Code:
if(joystick.getRawButton(4)
jaguar.set(1);
else if(joystick.getRawButton(5)
jaguar.set(-1);
else
jaguar.set(0);
|
Note: This will not create a toggle effect. If 4 is pressed, the motor will go forward and if 5 is pressed the motor will go in reverse, but it will not continue to go in that direction if you let go of the button. However, this is a good, simple solution to the problem you are facing. One thing to note about how this code will perform, if both buttons are pressed, the jaguar will go forward. One way to fix this is to replace the first line with
Code:
if(joystick.getRawButton(4) && !joystick.getRawButton(5))
It is a little bit longer, but will protect you from accidentally going in the wrong direction should you hit both buttons in the heat of competition. In order to have a true toggle effect, you will probably need a limit switch or potentiometer or other sensor to tell you when you are done going up or done going down. Hope this helps!
|