Looking to use 10 digital inputs to give an analog value for a Teensy 3.0. Going to use it as a joystick input for a little project I am doing.
The digital truth table looks like this -
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Analog |
---|---|---|---|---|---|---|---|---|---|---|
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1023 |
1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 921 |
0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 819 |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 717 |
0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 615 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 513 |
0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 411 |
0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 309 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 207 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 105 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
So pretty straight forward.
I just need to put that value into Joystick.X(value); and I am unsure of the cleanest way to do it.
In case it's not blindingly obvious, I am pretty new to code but not new to electronics so would appreciate long explanations where possible.