LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

elapsed time beginner

Thanks alot 🙂 I got the idea now .. 

another question .. 

after 15 seconds , and wen the LED was on , i want to add let's say a switch to turn it off again .. 

What is the best way to do such thing ? 

0 Kudos
Message 11 of 19
(791 Views)

@hah49 wrote:

Thanks alot 🙂 I got the idea now .. 

another question .. 

after 15 seconds , and wen the LED was on , i want to add let's say a switch to turn it off again .. 

What is the best way to do such thing ? 


One way to do this is to actually use a button (that looks like an LED) so it can turn itself off.  Otherwise, just have your switch wired to a local variable for the LED to set it's value to false.  You should to add some extra logic as well for the following considerations for functionality.

 

1.  Is the switch allowed to turn the LED on?

2.  When turning the LED off, do you want to restart the 15 second timers?

3.  Should the switch only be enabled/visible when the LED is on?

4.  etc.......

0 Kudos
Message 12 of 19
(788 Views)

the first method you said : Do you mean i can use the same block( which is a switch ) as an indicator and a control ? 

so that the timer will turn it on and i can turn it off?

0 Kudos
Message 13 of 19
(786 Views)

 

@hah49 wrote:

the first method you said : Do you mean i can use the same block( which is a switch ) as an indicator and a control ? 

so that the timer will turn it on and i can turn it off?


So-to-speak.  To programitically change the value of a control (your switch or button), wire the output of your Elapsed Time.vi to a "local variable" or "property node" for the boolean control.

 

Message 14 of 19
(781 Views)

Aha it worked 😄 thanks for the information 🙂 

but sadly i won't be able to use it since i should have a separate switch other than the LED .. 

So my last question of the day : 

 

I don't care about the other conditions such as if the switch is enabled , or if the timer should reset ,  etc..

I tried to wire the new switch to a local variable of the LED , but when i am running it it seems that she has no effect on the real LED ,

could you tell me why ?

 

network.png

and thanks alot for your time 🙂  

0 Kudos
Message 15 of 19
(770 Views)

Is that picture your entire block diagram?  If so, once the while loop exits, your program will stop running.  Therefore the switch will only be evaluated once.  And there is no way to know whether that is before or after your while loops since there is no dataflow control.  

 

In general, it is a good idea to encompass your entire program in a while loop controlled by a button on the front panel.  Your code will continue to run until this button is pressed.  You should classify your code segments by when they run (all times/during idle, after a button press, after data is returned, etc.)  This will help you organize your block diagram and ensure each segment only runs when it's supposed to. 

 

If you have some extra time take a look at the State Machine architecture, it's a nice way to compartmentalize your block diagram.  While there wouldn't really be much benefit in your current program, it helps to learn these things early.

0 Kudos
Message 16 of 19
(764 Views)

Ok this is my file . 

Everything is inside a while loop which means that the switch runs several times right ? 

And if so can you find the problem please ? 

 

0 Kudos
Message 17 of 19
(761 Views)

First, it's pointless to have "Mode Confirm" control two separate case statements which each have only a TRUE case.  Combine these.

 

Second, the reason why your switch isn't working is due to two reasons

1.  Since it's inside the case statement, when you press "Mode Confirm", it momentarily evaluates the switch value and then proceeds into the timer loop.  Going back to other previous comments, having the wait as the only thing inside the loop will prevent other code from running.  The main point is that you need to be periodically running the Elapsed Time.vi by some means (while this technically works, it blocks any other existing code from running).

 

Move your switch evaluation outside the case structure so it's evaluated independently of the Wait function.

 

2.  Change the Button's mechanical action to "Switch when pressed" or released.  With the current button action, it's value is only "true" when you are holding it down.  Revisiting point 1, this switch will be ignored until after the "wait loop" has finished.

 

Message 18 of 19
(750 Views)

thanks for everything ! 😄 regards 😄 

0 Kudos
Message 19 of 19
(736 Views)