Page 1 of 1

Inverting an Output

Posted: Thu Feb 22, 2018 7:37 pm
by streborc
I'm a newbie doing some really primitive programs to learn Flowcode7. My breadboard has a push button switch wired normally high. I wanted to create a program that simply reads the switch input, inverts the logic state variable, and outputs the variable to an LED. That is, I wanted the LED to be off when the switch input is normally high; and when the switch is pressed and its input pin goes low, I wanted the LED lit. I defined the variable "switch" to read the input pin and then I output "NOT switch" to the LED. "NOT switch" is accepted as a variable when defining the Properties: Output ("~switch" (tilda switch) is also accepted) as contextually correct, but either fails to simulate correctly -- the LED remains always on, and never changes state when the switch is pressed. (BTW, Properties:Input will not accept "NOT switch" -- the variable cannot be inverted when inputted.) If the Properties:Output variable is defined only as "switch", the LED responds to the switch as expected (normally on, and then off when the switch is pressed). ( I have the switch defined as active low in the simulation screen.) The only way I can get the LED to behave in the desired manner, that is, for the program to invert the variable "switch", is to define a new variable "nswitch" and insert a calculation step between the input block and the output block, with the calculation defined as "nswitch = NOT switch", and then output the variable "nswitch" to the LED. With this added step, the LED is on when the switch is pressed (input logic low), and the LED is off when the switch is released (input logic high). While this calculation step produces the correct result, it's curious to me that "NOT switch" is processed correctly when used in the Calculation function, but not correctly when used in the Output function (even though it's not flagged as illegal as it is if entered as an Input variable). Obviously, there are hardware solutions such as rewiring the switch, or reversing the LED polarity and referencing it to Vcc instead of ground. But my objective is learning Flowcode, and not coordinating the behavior of an LED and switch, so I would like to know how others accomplish variable inversion and similar function operations within the Output function.

Re: Inverting an Output

Posted: Thu Feb 22, 2018 11:03 pm
by medelec35
Hi streborc,
Please follow the forum rules:
5 The “Tips and Tricks” sub forum is for sharing your knowledge and NOT for starting off with asking questions.

I have moved your post to Flowcode V7 section.

Attached is a flowchart with two switches, illustrating two different ways to make an output go high - when the input is low.
Should work with both simulation and actual hardware

Martin

Re: Inverting an Output

Posted: Sat Feb 24, 2018 9:52 pm
by streborc
Further on this, I find that I can simply use the ! operator as a variable prefix to invert the switch state to the output per the attached.

Re: Inverting an Output

Posted: Sat Apr 06, 2019 5:03 pm
by Frank607
Thanks Martin. This was just what I’m looking for.

Regards,

Frank