input port bit slect using variable name

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Maverick
Posts: 68
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:58 am
Has thanked: 27 times
Been thanked: 8 times

input port bit slect using variable name

Post by Maverick »

Hi
Is there a way you can read the value of a port bit using a variable name to select the port bit used.

medelec35
Matrix Staff
Posts: 1429
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 505 times
Been thanked: 468 times

Re: input port bit slect using variable name

Post by medelec35 »

Hello.
The easiest way would be to use the switch icon.
Then you can add any input on any branch.
If for example, the value of the switch variable is 2 the branch which has 2 will be accessed.
That could have an input A2 for example
Martin

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: input port bit slect using variable name

Post by mnfisher »

An alternative technique...

Read the entire port and then shift to get the required bit..
Have something like:
Where .n is the variable holding the bit you want to read and .p is a variable as 'wide' as the port (so byte for 8 bits or long for esp32 (32 bits port)).

Code: Select all

.p = Input() // Read the whole port - click on Advanced options to allow this.
.bit = (.p >> .n)  & 1   // Extract the required bit.
Martin

Post Reply