Thread: Button coding
View Single Post
  #5   Spotlight this post!  
Unread 24-02-2016, 09:13
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,025
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Button coding

Quote:
Originally Posted by nlt5 View Post
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.
This sounds like the common coding error where one button is commanding the motor to go while the other is commanding it to stop.

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);

if (button2) {setmotor(-1)} else setmotor(0);


... then change it to this:
Code:
if (button1) {setmotor(1)} 
else 
if (button2) {setmotor(-1)}
else setmotor(0);



Last edited by Ether : 24-02-2016 at 09:17.
Reply With Quote