How do you toggle the value of a binary variable?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
F22-Raptor
Posts: 13
Joined: Fri Nov 20, 2009 2:58 pm

How do you toggle the value of a binary variable?

Post by F22-Raptor »

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.

F22-Raptor
Posts: 13
Joined: Fri Nov 20, 2009 2:58 pm

Re: How do you toggle the value of a binary variable?

Post by F22-Raptor »

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.

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: How do you toggle the value of a binary variable?

Post by Steve »

Use the output icon and set the output value to your variable, and select "single bit" mode.

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

Post by medelec35 »

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
Attachments
Toggle1.fcf
(6 KiB) Downloaded 330 times
Martin

F22-Raptor
Posts: 13
Joined: Fri Nov 20, 2009 2:58 pm

Re: How do you toggle the value of a binary variable?

Post by F22-Raptor »

Thanks guys. This is very helpful.

D.

Post Reply