Hi
Is there a way you can read the value of a port bit using a variable name to select the port bit used.
input port bit slect using variable name
-
- Posts: 69
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 02, 2020 10:58 am
- Has thanked: 27 times
- Been thanked: 8 times
-
- Matrix Staff
- Posts: 1921
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 623 times
- Been thanked: 645 times
Re: input port bit slect using variable name
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
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
-
- Valued Contributor
- Posts: 1462
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 136 times
- Been thanked: 713 times
Re: input port bit slect using variable name
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)).
Martin
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.