How to toggle a variable with a key?

Discuss issues and ideas you have to configuring displays with PowerVision
verschuren
Posts: 79
Joined: Wed Oct 28, 2015 8:40 am

How to toggle a variable with a key?

Post by verschuren » Fri Jan 15, 2016 1:53 pm

Hi,

How would I toggle a variable (FROM 0 TO 1) with one of the keys on the display?

Anyone?
Mario Verschuren
Controls Integration
stalley
Enovation Controls Development
Enovation Controls Development
Posts: 618
Joined: Tue Mar 18, 2014 12:57 pm

Re: How to toggle a variable with a key?

Post by stalley » Fri Jan 15, 2016 2:34 pm

IF(Var = 0, 1, 0)
Sara Talley
Software Engineer
Enovation Controls
verschuren
Posts: 79
Joined: Wed Oct 28, 2015 8:40 am

Re: How to toggle a variable with a key?

Post by verschuren » Fri Jan 15, 2016 4:08 pm

Thanks Sara, I will try that.
Mario Verschuren
Controls Integration
verschuren
Posts: 79
Joined: Wed Oct 28, 2015 8:40 am

Re: How to toggle a variable with a key?

Post by verschuren » Tue Jan 19, 2016 7:00 am

Hi Sara,

The expression you gave me works, but it sets the variable and maintains it. Is there a way that it will go back to it's original position, like a push button and not a toggle switch?

I guess I needed a slightly different use of the function.
Mario Verschuren
Controls Integration
stalley
Enovation Controls Development
Enovation Controls Development
Posts: 618
Joined: Tue Mar 18, 2014 12:57 pm

Re: How to toggle a variable with a key?

Post by stalley » Tue Jan 19, 2016 7:49 am

Good Morning Mario,

More like a momentary switch?

A state machine with two states should work.

State1-Initial: Fire a calculation event that sets the variable to 0
State2: Fire a calculation event that sets the variable to 1 and start a 500 (you can determine this for your need) ms One Shot timer

The event from State1 to State2 is the button press event
The event from State2 to State1 is the timer event

This would set the variable to 1 for the amount of the timer time and then return the variable to 0.

Does it make sense? You could do this with a script, but the state machine seems simpler to me, I like pictures ;-)
Sara Talley
Software Engineer
Enovation Controls
verschuren
Posts: 79
Joined: Wed Oct 28, 2015 8:40 am

Re: How to toggle a variable with a key?

Post by verschuren » Tue Jan 26, 2016 12:00 pm

Hi Sara,

I'm having some difficulties with this. I use the following expressions

Button Off: if(VAR_SenderCAN_Button = 0,1,0)
Button On: if(VAR_SenderCAN_Button = 1,0,1)
SM toggle.png
SM toggle.png (24.6 KiB) Viewed 143 times
The button is connected to UE SenderCAN Button.
UE SenderCAN Button TM is the 500 ms one shot timer.
Initial state has only the "button off" event in it.

I am checking functionality with a text gauge to see if the variable "VAR_SenderCAN_Button" switches between 0 and 1.

So far it doesn't work. I'm not sure why?
Mario Verschuren
Controls Integration
stalley
Enovation Controls Development
Enovation Controls Development
Posts: 618
Joined: Tue Mar 18, 2014 12:57 pm

Re: How to toggle a variable with a key?

Post by stalley » Tue Jan 26, 2016 12:57 pm

Where do you start the timer?

In your SenderCAN Tx Override state, I see you fire the event CE VAR SEnderCAN Button On, is this the event that sets the variable to 1?

Then you fire the event UE SenderCAN Button TM which transitions back to the Initial State. If this is the event with the timer, you should start the timer instead of firing the event.
Sara Talley
Software Engineer
Enovation Controls
verschuren
Posts: 79
Joined: Wed Oct 28, 2015 8:40 am

Re: How to toggle a variable with a key?

Post by verschuren » Tue Jan 26, 2016 1:40 pm

CE VAR SEnderCAN Button On is the event to set the button to 1.

UE SenderCAN Button TM is the timer event, I will change that to the timer itself. I was planning to start to timer in the 2nd state.

I also made a mistake with the two expressions.
verschuren wrote: Button Off: if(VAR_SenderCAN_Button = 0,1,0)
Button On: if(VAR_SenderCAN_Button = 1,0,1)
It should be:

CE VAR SEnderCAN Button Off: if(VAR_SenderCAN_Button = 1,0,1)
CE VAR SEnderCAN Button On: if(VAR_SenderCAN_Button = 0,1,0)

After changing the timer in the 2nd state, it toggles on and off. For some reason it returns 1 in non active state. When you press it's 0. Not sure why that is.
Mario Verschuren
Controls Integration
verschuren
Posts: 79
Joined: Wed Oct 28, 2015 8:40 am

Re: How to toggle a variable with a key?

Post by verschuren » Tue Jan 26, 2016 2:11 pm

It works now. I did change the button events again and that made it work.
verschuren wrote:
verschuren wrote: Button Off: if(VAR_SenderCAN_Button = 0,1,0)
Button On: if(VAR_SenderCAN_Button = 1,0,1)
It should be:

CE VAR SEnderCAN Button Off: if(VAR_SenderCAN_Button = 1,0,1)
CE VAR SEnderCAN Button On: if(VAR_SenderCAN_Button = 0,1,0)
Final result:

CE VAR SEnderCAN Button Off: if(VAR_SenderCAN_Button = 1,0,0)
CE VAR SEnderCAN Button On: if(VAR_SenderCAN_Button = 0,1,1)
Mario Verschuren
Controls Integration
stalley
Enovation Controls Development
Enovation Controls Development
Posts: 618
Joined: Tue Mar 18, 2014 12:57 pm

Re: How to toggle a variable with a key?

Post by stalley » Tue Jan 26, 2016 2:15 pm

I would recommend taking out the IF in your calculation events, they aren't needed for your state machine. You want to set your variable to 0 in the Initial state and 1 in your second or On state. Your state machine is controlling the conditions.
Sara Talley
Software Engineer
Enovation Controls