Page 1 of 1
variable input-, or output port
Posted: Sun Dec 10, 2017 2:55 pm
by Jan Lichtenbelt
I want to change the port by the flowcode software.
In this example here, for port A. The port number will be determined by the software variable APort.
E.g. value 1 as output to APort. In C-code this will become:
FCP_Set(B, A, 1<<FCV_APort, FCV_Aport, (1));
And input to variable AIn:
FCL_Ain= FCP_Get(B, A, 1<<FCV_APort, FCV_Aport);
Is this correct? Is there an easier way?
By the way, what is B in FCP_Set(B.... and FCP_Get(B....
Kind regards
Jan Lichtenbelt
Re: variable input-, or output port
Posted: Mon Dec 11, 2017 11:18 am
by Benj
Hi Jan,
The easiest way to allow for a dynamic port is using a property. This can be made to be a single digital pin, a digital port or an analogue pin. This is one of the corner stones of component creation.
Here is how to create a property.
https://www.flowcode.co.uk/wikiv7/index. ... a_Property
Then in a calculation icon you can refer to the property variable, for example propvar.
To write a value to the port/pin.
propvar = 0
To read a value from the port/pin.
flowcodevar = propvar
This will then also simulate.
Re: variable input-, or output port
Posted: Mon Dec 11, 2017 2:45 pm
by Jan Lichtenbelt
Hi Ben
Thanks for your answer.
The easiest way to allow for a dynamic port is using a property.
I'm afraid that is not the easiest way for me. It looks complicated to me. But be never to old to learn something new. I will try.
But does it mean that my C-code solution is not correct?
Kind regards
Jan
Re: variable input-, or output port
Posted: Mon Dec 11, 2017 3:15 pm
by LeighM
Hi Jan
Your question about the "B", this ensures that the C "Bit" macro is used.
Your C code will work, but only for a variable pin in a fixed port.
But it's probably not a good idea to use our internal macros like that as they might change.
Using a property to define the port and pin at compile time as Ben suggests is the best way,
unless the question is that you need to change the port and pin based on a variable that can change at run time?
If that is the case, then maybe you could write a function, aka Flowcode macro, say GetInput(x)
that takes a variable as a parameter, then in the GetInput() macro you use a switch to read the port/pin required for that variable value.
Similar for output, SetOutput(x, value)
If all the inputs are on the same port, then it would be easier just to read the port then mask the pin that you want.
All depends on exactly what you are trying to do.
But hope that helps.