Programming 2 buttons for a relay

Hi, I’m trying to get button one on my controller to make the relay go forward, and button 2 on my controller to make it go in reverse. I have a picture of what i have so far and if anyone else can remake this picture and put in the changes it needs to make this works that would be great!

Thank you

Keep in mind that the way you wrote it, the optional code is producing the constant, but you are still calling the relay function regardless of what the buttons do. In fact you are calling it twice. Try putting the subVI inside of the case statement too. That way if button one, you send the one value to the relay. In parallel, if button two, send the other command to the relay. If neither button, don’t do anything to the relay.

Greg McKaskle

Is it possible for you to put this into labview, and send it over as a picture. I’m an 18 year old with about 0 experience on LABVIEW and officially don’t know what i’m doing.

Not super easy. If you open the diagram that you took a picture of, click on the relay and drag it to the left into the case structure next to it. Then reconnect the pink wire to the upper left. Then do the same to the other relay. Then test.

Greg McKaskle

I tried it, and it didn’t work. What happens is button 1 will do the reverse command, but button 2 remains unresponsive.

I suspect the code is doing what you told it, just not what you wanted. If you right click, you can set a breakpoint on the relay function inside the case for button two. Then you will know for sure that the button is setting the relay off.

The next question is, what does turning off the relay really do on your robot.?Is that the right thing to do? Changing the constant to other values may be the right thing. Be safe, especially if this is controlling pneumatics.

Greg McKaskle

Have you tried the diagram detailed in the image?

You would need to change the Reverse to Off, and in the True Case, set the relay to Reverse.

relay 2 button.JPG

relay 2 button.JPG

But, i would need to put the “and” function into both cases? or do i only need one?

well, the “and” block is outside the case structure. so you shouldn’t need to put in two of them.

But how do i set it between, forward, off, and reverse, or will it do that automatically

ok, inside the case structure, True will execute when both are pushed, and false will execute if anything else is pushed. inside of that, pick which one you want it to do. just change where it says “reverse” or “off” or whatever.

Hey i am also trying to do the same thing. I think that there is a bug in labview. I Opened up two joysticks and wired 2 buttons to their own select function. On the first select function, the true statement was forward and the false statement was 0, i wried that to the false statement of the second select function. On the second select function’s true statement was reverse. It was wired to a relay set and wen i ran the program both of the leds light up when i push the button but the relay will only go in one direction. I did the same code for a motor and it worked just fine so i think that the relay vi. has a bug in it

We’ve worked a couple of examples demonstrating programming joystick buttons for different robot functions.

Joystick Button Control (Using a Functional Global Variable)

Hi, Here is some code that avoids using case statements since it seemed overkill. We ran into the problem in which the red light would appear to be blinking at a fast rate and flickering. We resolved this issue by ensuring that a relay command is given only once during each execution. We did this by using select blocks. The true and false signals are enum constants in which I just copied from the relay set vi (right click on the input for the relay set vi and create as constant then make multiple copies of that to put as inputs to the select blocks). For our code, we set one button for forward and another for reverse. When either both or none of the buttons are pressed, the relay defaults to the off state. We are actually controlling two relays with the same control signals so you will see two relay set vis, just ignore the second one. I attached a picture.

This was a little too much but for forward and reverse we created boolean equations that are represented by the logical ands and ors that you see in the code.

I really hope this helps! If you have further questions feel free to ask!

Hello, Im having some issues with something similar to this. I have 2 relays connected to window motors that are controling the arm movement. They are already inverse from eachother so i dont have to invert it on the code. What im having trouble with is im using the Y-axis on the joystick to control it, and when i push it forward, it works, but if i pull it back, it wont go back. :confused: i really need help with this. i keep looking over the code and it seems logical, i guess is some minor detail. I would Post a pictrue of the code but im not able to at the moment. This would help me so much if i could get an example. Team 3518 will greatly apreciate the service.

Are you trying to connect the joystick output directly to the relay input? That’s not going to work. The joystick axis provides a value that ranges from -1 to +1. The relay wants a specific enumerated value. I could explain why neutral and forward work while back does not, but that wouldn’t really help you. I’ve attached a picture showing how I would suggest doing it.

If you aren’t trying to wire a joystick to a relay with nothing between them, never mind. I’ll have to see your code to give any useful advice.