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: 

Switching State with Boolean Button Press/Counter/Timing

Solved!
Go to solution

I would like to have one (boolean) button change the state of several digital output lines (Picture attached):

 

Wit a button press, I want to create a short pulse (lets say 200ms) on lines 3 and 4 (simultaneously). After those 200ms, I want line 1 to switch states (let's say it was OFF until now, switch to ON), and line 2 doing the opposite (ON until now, OFF onwards). I would like each button press to create that short pulse on lines 3 and 4, and switch states on line 1 and 2.

 

This might be a simple VI, but I could not figure it out. I want this to go to a DAQ (USB 6211).

 

I hope I was able to explain it clearly.

 

Thank you bery much

0 Kudos
Message 1 of 16
(4,571 Views)

What have you tried?  Have any code to share?

 

This sounds to me like a simple state machine application.  Keep the states of your buttons with a shift register and have the state machine go through your output states.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 16
(4,542 Views)

Yes, correct, I am using a state machine, trying to use it with a shift register. 

 

Right now, I have four boolean buttons, one for each state. 

I don't know what goes inside the state machine, i.e. how to wire everything. I am pretty lost, even when looking at examples and tutorials.

0 Kudos
Message 3 of 16
(4,525 Views)

First, write down what states you will need, what you need done in each state, and how you want to transition from one state to the next.  I am specifically referring to a State Diagram.  Then we can start looking at code.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 16
(4,507 Views)

I have two states, both state toggled by a singled button. I have four variables in both states. S1 when button = true, S2 when button = false.

The transition between both states is to run c and d for 100ms each. I tried drawing it in the picture from the original post.

 

Thank you

 

0 Kudos
Message 5 of 16
(4,483 Views)

Looks like my attachment didn't get uploaded in my last post. Here it is

0 Kudos
Message 6 of 16
(4,460 Views)

@tuyenhoang7 wrote:

I have two states, both state toggled by a singled button.


No.  Based on what you have said, you will want a state for each transition plus a state for checking for the user pressing buttons.  Then you can check for the user pressing a button and starting up your new sequence.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 16
(4,453 Views)

Is checking for the button (whether or not the user has pressed it) a transition or a state? I have envisioned it to be a transition, so that each state would do something (or nothing), and the buttons would be the transitions (whether or not the button is pressed).

 

I am attaching what I think my state machine should look like. Please let me know if this makes sense.

S0 would be the initial state, doing nothing.

 

0 Kudos
Message 8 of 16
(4,431 Views)

Checking of the buttons is a state.  The state of the buttons being pressed or not causes a transition.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 16
(4,422 Views)

That makes sense. The diagram attached from my last post shows three states. Can checking the button could be part of the DO statement? Or does it need to be a separate state? The arrows/transitions would be the state of the buttons being pressed, with B = Y being 'button pressed', and B = N being 'button not pressed'.

 

 

0 Kudos
Message 10 of 16
(4,399 Views)