08-28-2018 03:34 PM
Hello NI Labview community,
I'm new to Labview, and I'm trying to use an event structure (I'm aware of the case structure but I want to learn it, by using an event structure) to convert a temperature of unit degrees celsius to either kelvin or fahrenheit.
My obective is, that when the button is toggled upwards, i want to convert the temperature Fahrenheit, and when it is toggled down, to Kelvin (As shown in the first picture).
I've succeeded in converting the temperature to Fahrenheit by detecting change in the value of the input temperature.
But I'm struggling with converting the temperature by toggling the button up or down by using the event structure. The code I've written in picture 2 and 3 changes the temperature to Fahrenheit ONCE, no matter how many times I i toggle it up or down while the code is running.
And, how can I convert the input temperature to celcius? Labviews doesnt allow me to do it by adding a new event case, as that would require a change in input temperature and toggling the button. But since these 2 variables already are used to convert to fahrenheit, i cant choose them again for a new event case.
I hope you understand my question.
08-28-2018 03:41 PM
You need a case structure that determines which formula to use to either output Celsius or Fahrenheit. Right now you have a single formula and you don't do anything with the position of the toggle switch.
Your toggle switch talks about output Kelvin or Fahrenheit. Nothing in your VI mentions Celsius.
Your input control should be put inside the event structure. Otherwise if you change the input, it will fire the event, but will be using the value that was read before the code stopped and waited for the value change event.
08-28-2018 03:41 PM - edited 08-28-2018 03:44 PM
08-28-2018 03:46 PM
Thank you for your reply!
So you're suggesting that I use the event structure inside a case structure - 1 case for Fahrenheit and another case for celsius?
08-28-2018 03:50 PM
No, a case structure inside the event case, each case having a different scaling of the input.
08-28-2018 03:56 PM
@Altenbech
Thank you, I praise your effort for trying to explain this to me.
But I find it very difficult to understand what you're suggesting. Could you please explain it again? If I put a case structure inside event structure, does that mean, the Case structure detectes change in toggle position only, and the event structure detected change in input temperature only?
08-28-2018 04:14 PM
Could you please look at what I'm doing wrong? I can't make it work.
08-28-2018 04:40 PM - edited 08-28-2018 04:41 PM
I might have been unclear regarding the objective of this exercise: When the button is toggled upwards (ON), then the temperature should be converted to Fahrenheit and displayed on the thermometer. If it is toggled downwards, then temperature should be shown on the thermometer in Kelvin (Not celcius as i earlier said, sorry!).
The VI i uploaded did this, I think. Feedback is much appreciated.
But i got further questions, to improve the code:
1) How can i use a property node to use the unit of the temperature to adjust the scale of the thermometer? For example: If the button is toggled upwards, the unit i Fahrenheit, and the scale of th thermometer should go from 0-200. If it is Kelvin it should go from 200-350?
2) How can I make the button position (toggled upwards/downwards) decide the name/value of labels? For example if it is toggled upwards, I would like a label next to the temperature displayed "Fahrenheit"?
08-28-2018 05:13 PM - edited 08-28-2018 05:14 PM
@Antaras wrote:The VI i uploaded did this, I think. Feedback is much appreciated.
I would use a radio-button instead of a switch. Now you can add other units later and the case structure cases are self-explanatory.
You don't need a seperate event case for the stop button, You can use one event case for all events.
You can use a timeout to update all indicators correctly once when the program starts. Later, the timeout is -1 (infinite)
Here's a quick draft.
@Antaras wrote:But i got further questions, to improve the code:
1) How can i use a property node to use the unit of the temperature to adjust the scale of the thermometer? For example: If the button is toggled upwards, the unit i Fahrenheit, and the scale of th thermometer should go from 0-200. If it is Kelvin it should go from 200-350?
2) How can I make the button position (toggled upwards/downwards) decide the name/value of labels? For example if it is toggled upwards, I would like a label next to the temperature displayed "Fahrenheit"?
Yes, the magic words is "property node" The thermometer has properties for scale.range.max/min, so place such a property node after the case structure and feed appropriate constants in each case to set these accordingly. You can add a string indicator after the case structure that gets a different string depending on the case. etc. See how far you get. ...