10-18-2013 11:38 AM
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 ?
10-18-2013 11:47 AM
@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.......
10-18-2013 11:57 AM
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?
10-18-2013 12:07 PM
@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.
10-18-2013 12:29 PM
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 ?
and thanks alot for your time 🙂
10-18-2013 12:39 PM
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.
10-18-2013 12:54 PM
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 ?
10-18-2013 01:26 PM - edited 10-18-2013 01:26 PM
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.
10-18-2013 02:39 PM
thanks for everything ! 😄 regards 😄