![]() |
How to toggle a relay with one button?
I need to turn a relay on and off your one button on the joystick. Much like a toggle button. Could some one give me some sample code?
|
Re: How to toggle a relay with one button?
Here's a generic button toggle example:
![]() Put one Relay set in the inside True case, the opposite set in the inside False case. |
Re: How to toggle a relay with one button?
What are the green arrows?
|
Re: How to toggle a relay with one button?
The green arrow is found on the Programming -> Structures palette.
It's called a Feedback node, and what it does for you is remember the previous value, so the current value can be compared to the previous value. So for the button press the value can be thought of as 0 (false) or 1 (true). That first peculiar little combination is checking to see of the button is going from off (the previous value) to on (the current value), so it's only true the very first time you press the button and won't be true again until the button is release and pressed again. To change the arrow direction once you put it on your block diagram, right-click and choose Change direction. |
Re: How to toggle a relay with one button?
How does the arrow become green? I found the arrow, but it is black.
|
Re: How to toggle a relay with one button?
It changes color based on the data type that then gets wired to it.
It's green in the example because a boolean wire got connected to it. So it'll turn green when you wire the button output to it. If you wired an integer to it, then it would turn blue. A floating point number would make it orange instead. |
Re: How to toggle a relay with one button?
Thank you very much! It worked
|
Re: How to toggle a relay with one button?
What about false in the outer case structure of?
|
Re: How to toggle a relay with one button?
The outer false case avoids doing anything at all.
That's when the button hasn't been pushed again. The wire just gets passed from the input tunnel right to the output tunnel. |
Re: How to toggle a relay with one button?
2 Attachment(s)
One of our veteran team members wrote a very simple and effective Toggle vi, which I've attached. Just feed the button signal into the input, then use the output with a select block or case structure to select your relay state.
|
Re: How to toggle a relay with one button?
1 Attachment(s)
I was asked to provide a screenshot of what our team's Toggle VI looks like, so here's how it works!
|
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
Ugh. The LabVIEW Developer in me can't stand feedback nodes. They make everything so much harder to understand.
|
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
I understand them, but they break left to right data flow, which is considered a no-no in most of the LabVIEW world.
I prefer to use shift registers and while loops. |
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
Generally, yes.
I find that vi to be difficult to understand, as the loop that causes the feedback nodes to contain data is outside the scope of the vi. Tracking the flow of the program gets much harder that way. |
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
1 Attachment(s)
This would have identical function to the other one. Similar in compactness, and IMO easier to understand what is happening. Its a style thing though, I fully understand that other people may find feedback nodes easier to understand.
Attachment 15042 |
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
Quote:
|
Re: How to toggle a relay with one button?
Quote:
Personally, I find it difficult. Especially without the loop there to show that the code you're looking at is actually being called in a looping fashion to populate the feedback nodes. I'm pretty sure its a personal preference thing though. I have little-to-no experience with using LabVIEW in an FRC environment. Are we able to use event structures? Most of the LabVIEW programs I write make heavy use of the Event Structure to control process flow. |
Re: How to toggle a relay with one button?
Teams can use event structures, but few do. This is RT, so very little UI and not much need for user events.
As for the shift register versus feedback node. It took awhile for me to warm up to the feedback. I was so used to doing it with loops. I now use a mix. I typically use a shift register if it already has a loop or if it is a functional global. I use a feedback node if it is like the button example and is super local. I find that I change direction on the node when doing a compare for change, it makes much more sense to me. If I need the i-1 term for something else, I typically leave it in the default direction. I don't go for separating the init from the feedback. As you say, it is a style decision. Greg McKaskle |
| All times are GMT -5. The time now is 22:56. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi