View Full Version : Problems with buttons and structures
skylerashe
18-02-2014, 13:10
I am attempting to make two motors run at the same time when a button is pressed and stop when its released I have gotten it to work for one button but I need it reversed with the second and its very glitch when I try that it runs like every five seconds which I find very strange here is the code for reference http://imgur.com/y21fcb6 I have the false set to zero for the motors to stop running thanks for any help
Mark McLeod
18-02-2014, 13:24
You can't set the same motor to different values in two different places at the same time in your code.
One motor = one call to Set
You are telling the motors to go and to stop at the same time.
Whichever code gets executed last wins the race.
If you have the false cases setting the motors to zero then you have the same code turning the motors on and turning the motors off. (ie when you press button 2, the first case statement evaluates as false, setting the motors to zero, the second case statement evaluates to true, which tries to turn the motors on) The order of execution is indeterminate in the code you provided which means that you're going to get unpredictable results.
There are a couple of ways to achieve what you want. One would be to nest the two case structures. (check button 2 in the false case of button 1). Another would be to use cascading select blocks to determine which value to send to the Set Motor blocks.
Hope that helps.
skylerashe
18-02-2014, 13:29
Ok I see where my error is now but I don't quite get how to fix it any examples of something similar?
Mark McLeod
18-02-2014, 13:31
Here's an example of the cascading select blocks that Dave mentioned:
http://team358.org/files/programming/ControlSystem2009-/LabVIEW/ButtonMotor.png
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.