Inverting an Output
Posted: Thu Feb 22, 2018 7:37 pm
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.