How to toggle a variable with a key?
- verschuren
- Posts: 79
- Joined: Wed Oct 28, 2015 8:40 am
How to toggle a variable with a key?
Hi,
How would I toggle a variable (FROM 0 TO 1) with one of the keys on the display?
Anyone?
How would I toggle a variable (FROM 0 TO 1) with one of the keys on the display?
Anyone?
Mario Verschuren
Controls Integration
Controls Integration
- stalley
- Enovation Controls Development
- Posts: 618
- Joined: Tue Mar 18, 2014 12:57 pm
Re: How to toggle a variable with a key?
IF(Var = 0, 1, 0)
Sara Talley
Software Engineer
Enovation Controls
Software Engineer
Enovation Controls
- verschuren
- Posts: 79
- Joined: Wed Oct 28, 2015 8:40 am
Re: How to toggle a variable with a key?
Thanks Sara, I will try that.
Mario Verschuren
Controls Integration
Controls Integration
- verschuren
- Posts: 79
- Joined: Wed Oct 28, 2015 8:40 am
Re: How to toggle a variable with a key?
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.
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
Controls Integration
- stalley
- Enovation Controls Development
- Posts: 618
- Joined: Tue Mar 18, 2014 12:57 pm
Re: How to toggle a variable with a key?
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 ;-)
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
Software Engineer
Enovation Controls
- verschuren
- Posts: 79
- Joined: Wed Oct 28, 2015 8:40 am
Re: How to toggle a variable with a key?
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)
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?
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)
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
Controls Integration
- stalley
- Enovation Controls Development
- Posts: 618
- Joined: Tue Mar 18, 2014 12:57 pm
Re: How to toggle a variable with a key?
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.
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
Software Engineer
Enovation Controls
- verschuren
- Posts: 79
- Joined: Wed Oct 28, 2015 8:40 am
Re: How to toggle a variable with a key?
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.
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.
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.
It should be:verschuren wrote: Button Off: if(VAR_SenderCAN_Button = 0,1,0)
Button On: if(VAR_SenderCAN_Button = 1,0,1)
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
Controls Integration
- verschuren
- Posts: 79
- Joined: Wed Oct 28, 2015 8:40 am
Re: How to toggle a variable with a key?
It works now. I did change the button events again and that made it work.
CE VAR SEnderCAN Button Off: if(VAR_SenderCAN_Button = 1,0,0)
CE VAR SEnderCAN Button On: if(VAR_SenderCAN_Button = 0,1,1)
Final result:verschuren wrote:It should be:verschuren wrote: Button Off: if(VAR_SenderCAN_Button = 0,1,0)
Button On: if(VAR_SenderCAN_Button = 1,0,1)
CE VAR SEnderCAN Button Off: if(VAR_SenderCAN_Button = 1,0,1)
CE VAR SEnderCAN Button On: if(VAR_SenderCAN_Button = 0,1,0)
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
Controls Integration
- stalley
- Enovation Controls Development
- Posts: 618
- Joined: Tue Mar 18, 2014 12:57 pm
Re: How to toggle a variable with a key?
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
Software Engineer
Enovation Controls