![]() |
Button coding
Can someone help me with the code that would be used to have a motor come on when a button is pressed. I can get the motors to turn on and off with the press of a button but I want the motor to run while the button is pressed then when the button is released the motor stops.
Thanks for all the help on this forum, what a great resource for new teams. Oh and I am using iterative |
Re: Button coding
Code:
if(joystick.getRawButton(buttonNumber) |
Re: Button coding
Great,
thank you very much |
Re: Button coding
So I wrote the code and was able to get this to work for the motors in one direction. I would press and hold the button, the motors would spin, and when I released the button they would stop. We want the motors to spin in both directions so I wrote additional code and set the motors to -1 using a different button. When I ran the code the motor would pulse at different rotational rates. When I would program to use 2 buttons, one for on, one for off the pulsing would stop. Any ideas??? I'm not sure why in one direction the motor spins fine but in the other they pulse.
thanks |
Re: Button coding
Quote:
You need to change your if/then/else logic so that only one command is issued to the motor(s). if your code looks something like this: Code:
if (button1) {setmotor(1)} else setmotor(0);... then change it to this: Code:
if (button1) {setmotor(1)} |
Re: Button coding
Sounds good,
I will test in about a month when it is legal to unbag our robot. Thank you very much. |
Re: Button coding
Quote:
|
Re: Button coding
Quote:
Code:
if(joystick1.getRawButton(buttonNumber) |
Re: Button coding
Thank you. Looks like it's working.
|
| All times are GMT -5. The time now is 07:59 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi