From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hold button input through multiple events

Solved!
Go to solution

I am fairly new to LabView and have a traffic light project I need to do. Everything seems to work but I can't get my crosswalk buttons to work unless they are pressed during a certain event. I have tried using a feedback node and a shift register but neither one is giving me the desired results. 

0 Kudos
Message 1 of 17
(3,336 Views)

Ouch! Try to do ity without a single local varaible or sequence structure! You can shrink your code to 10% of the complexity it has now!

 

Maybe you want to use a different mechanical action for the buttons.

 

(Note also that you have coercion dots on the state enum, meaning that not all are the same. Don't talk about events if you don't even use an event structure. Try to wire left-to-right and not all over the place.)

0 Kudos
Message 2 of 17
(3,330 Views)

As Altenbach said, and you should look at an event structure. They can handle multiple controls in one event and get rid of the boolean as well.

Glad to answer questions. Thanks for any KUDOS or marked solutions 😉
0 Kudos
Message 3 of 17
(3,316 Views)

This is my first time using LabView and this project is due tomorrow. I have spent weeks trying to get this to work and I don't have time to try to start from scratch. I've tried using different mechanical actions for my buttons without any luck. I'm not sure what you mean about coercion dots? I thought I was using an events structure.

0 Kudos
Message 4 of 17
(3,313 Views)

No event structure anywhere! You are mixing two different enums, each with different items as state variable. That's a really bad idea. Use one enum that contains all states.

 

For me, starting from scratch would probably take 10 minutes to finish the program, while trying to fix your code would take half a day (exagerrating, of course!)

 

Plan out the code first:

  • You have N states, each with an associated duration. Think what they are!
  • Create an enum with one item for each state. The shutdown state should stop the outer while loop.
  • Make one case structure with cases for each state. (wire the enum to the selector and right-click create case for every value)
  • line up all indicators to the right of the structure (uncheck show as icons and move the label to the right). Arrange them into logical groups.
  • Place a TRUE diagram constant before the case structure and wire into the case and to all the output tunnels that need to be true for a given state.
  • Some indicators always match in value, so only one tunnel out of the case structure is needed. Branch the wire later.
  • make the tunnels "use default if unwired". No need to wire all these FALSE constants.
  • Place the wait after the case and wire the desired duration from inside each case.
  • Before the case structure, read the relevant buttons and decide what the next state should be based on their values.

Hey look! No local variables, no inner cases,  and no sequence structures. It's magic! See how far you get. Good luck!

 

(Yes, you could also use an event structure instead of the case structure and use the timeout (kept in a shift register) to time the states. I don't recommend to do that with your experience and deadline).

 

0 Kudos
Message 5 of 17
(3,292 Views)

I'm not sure exactly what you mean by "crosswalk button".  It's hard to identify everything on there.

 

Also, if you could attach the missing control "STATE.ctl" we could actually try running it...

0 Kudos
Message 6 of 17
(3,255 Views)

Your crosswalk buttons are set to "Latch Until Released". To fix your problem, change them to Latch When Released and move the value read terminals inside of the appropriate case. This will let the values stay the way they are until your read the value in the case that cares about it. No shift registers needed and each crosswalk button type (N-S or W-E) gets handled separately.

Wacky Waving Inflatable Arm Flailing Boolean Man.png

 

Your VI needs much improvement past that, so here are some critiques:

 

This VI is very hard to wrap one's head around.

  • You have way too many buttons that could be organized in clusters and you have zero documentation to go with the buttons. Double click on the block diagram to insert text.
  • Your State indicator has values of "Analog Output and Input", "Display One Electrode", "Display Movie", and "Stop"> So those must be outdated. This is why you see the little red coercion dots. Replace all of the enums with your type-defined enum (matching values appropriately) and your states will be easier to read.
  • You have the mismatched state enums that seem to be triggered by "ST" and "NT" Not sure what those two added booleans do...
  • All of those local variables at the top writing to themselves is completely useless, so I removed them from the above snippet.

 

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 17
(3,241 Views)

So I started from scratch... I am having the same issues with the crosswalk buttons plus I also am not sure how to wire my crosswalk switches and turn switches in case "EW Y". At least my project looks more presentable 🙂

0 Kudos
Message 8 of 17
(3,223 Views)

Hey, that really looks much better!!!

 

 

I'll have a look at your logic but you probably need to retain the switch values until the respecitive lights are serviced, not just until the next iteration.

0 Kudos
Message 9 of 17
(3,212 Views)

Here's a very quick draft how you would retain the TRUE until the relevant optional case has been sheduled of one of the buttons got triggered.

 

(Note that the code is not complete. You need to make sure all states are reached (e.g. the NW S buttons an others in that group are currently not read!)

0 Kudos
Message 10 of 17
(3,196 Views)