Inverting an Output

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
streborc
Posts: 4
Joined: Wed Jan 31, 2018 5:07 pm
Been thanked: 2 times
Contact:

Inverting an Output

Post 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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Inverting an Output

Post 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
Attachments
Act low1.fcfx
(10.69 KiB) Downloaded 244 times
Martin

streborc
Posts: 4
Joined: Wed Jan 31, 2018 5:07 pm
Been thanked: 2 times
Contact:

Re: Inverting an Output

Post 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.
Attachments
Flowcode8.fcfx
(7.08 KiB) Downloaded 260 times

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Inverting an Output

Post by Frank607 »

Thanks Martin. This was just what I’m looking for.

Regards,

Frank

Post Reply