I would like to read a binary variable (ExtendedMode)and take an action based on it's value (0 or 1).
What I'm struggling with this variable will be set by a push button.
So for example, the program starts running my my variable ExtendedMode is initialized with a value of 0, now a momentary push button is pressed and I want my ExtendedMode to be 1 until next time when the button is pressed again when I want it to toggle back to 0.
Can you use something like ExtendedMode = !ExtendedMode or is there some trick I'm supposed to use?
Thanks
D.
How do you toggle the value of a binary variable?
Moderator: Benj
-
- Posts: 13
- Joined: Fri Nov 20, 2009 2:58 pm
-
- Posts: 13
- Joined: Fri Nov 20, 2009 2:58 pm
Re: How do you toggle the value of a binary variable?
OK, so I just tried the var = !var and it works (in a calculation Macro), now this might me stupid but how do I use my new value to turn no an LED?
If I use the component macro it tells me to select a macro (LED(0)), if I use an output macro it sets my variable to 1?
D.
If I use the component macro it tells me to select a macro (LED(0)), if I use an output macro it sets my variable to 1?
D.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: How do you toggle the value of a binary variable?
I have created a basic toggle version for you. This has no switch de-bounce, which can be easily added. I have not use switch macro just in case you want the routine to run and do other things.
All you have to do is set all you own config parameters up i.e type of chip, osc speed, watchdog off etc.
Note: Using var = var XOR 0b00000001 will also toggle
All you have to do is set all you own config parameters up i.e type of chip, osc speed, watchdog off etc.
Note: Using var = var XOR 0b00000001 will also toggle
- Attachments
-
- Toggle1.fcf
- (6 KiB) Downloaded 330 times
Martin
-
- Posts: 13
- Joined: Fri Nov 20, 2009 2:58 pm