LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure for temperature conversion

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.
Udklip.PNGUdklip.PNGFP.PNG

0 Kudos
Message 1 of 9
(4,086 Views)

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.

0 Kudos
Message 2 of 9
(4,081 Views)
  • Your input control belongs inside the event case, else it gets read before the event fires and once the event fires, you get the stale data stored in the tunnel.
  • Your boolean does not change any math.
  • You need an event assignment for the stop button.
  • You should not use a formula node for simple math.
0 Kudos
Message 3 of 9
(4,079 Views)

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?

0 Kudos
Message 4 of 9
(4,070 Views)

No, a case structure inside the event case, each case having a different scaling of the input.

0 Kudos
Message 5 of 9
(4,062 Views)

@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?

0 Kudos
Message 6 of 9
(4,056 Views)

Could you please look at what I'm doing wrong? I can't make it work.

0 Kudos
Message 7 of 9
(4,039 Views)

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"?

 

0 Kudos
Message 8 of 9
(4,029 Views)

@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. ...

0 Kudos
Message 9 of 9
(4,013 Views)