button Switch

Is there anyway so that when you press a button on a joystick it starts a motor, when you let go it continues going. And then when you press it again the motor stops. Is there a way to do this?

This is actually a really simple issue for programming. The exact implementation depends on your programming environment. Here is how you would do it in C/C++:


bool motorIsRunning = false
...
if (theButton == PRESSED)
{
    motorIsRunning = !motorIsRunning;
}

...

if (motorIsRunning)
{
    motorValue = FULL_FWD;
}
else
{
    motorValue = STOP;
}

The one thing that this code will do that is different than what you are looking for (perhaps) is that if you hold down the button, it will continue to flip the motor flag. Of course, this is easy to fix, if you think about it.

Good luck,
Paul

Our team uses Labview. That’s where the issue is because there isn’t a “toogle” vi there

Our team has hit a snag here, too. We’re trying to run a Victor whenever we push a button, but Labview doesn’t seem to have an easy way of doing this, unfortunately.

I don’t know how to use LabView (to me it’s a waste of time) and I’m not involved with the programming on my team. However, you can still create a variable in labview (make it a boolean, an integer, a double, who cares). And then make it TRUE or 1 when you press the button and flip it each successive press. And then assign the motor value based on that.

-Paul

To remember something from one time you process joystick data to the next you need to use either a shift register, a feedback node, a local variable, or a global variable. Any of these will work. Then you do to that storage what the code above showed. You sometimes flip it, and use its value to affect the motor speed.

Greg McKaskle

I’m not sure exactly what to use but I think it would involve shift registers or select vi’s

I made a primitive toggle switch. But it will only activate/deactivate at a precise time. Probably like every millisecond or something. This is a picture of what we have. The only issue is the starting and stopping at the right time.

Toggle issue.PNG


Toggle issue.PNG

You would use shift registers.

Create a false constant outside of your loop, and feed it to the shift register initializer, then have your joystick button feed the case indicator of a case structure. in the true case, put an inverter (NOT gate, on the Boolean tab), in the line, in the false case, just run it straight through. now feed that to the shift register output. tee the motor on/off into that wire now. I hope that made sense, I’d make a simple vi and show you, but i dont have LabVIEW on this pc.

Here is a code that I made for our team. I used a flag to prevent the switch from switching back and forth. FYI, you might have to change things a bit(even though there’s not many stuff) for your project.

Switch rev.2.vi (11.3 KB)


Switch rev.2.vi (11.3 KB)

Hey,

Good idea that, using a sleep timer to keep from reading the joystick button press over and over. Here’s my solution.

Toggle.vi (13 KB)




Toggle.vi (13 KB)