I'm using an ESP32 and a ADS1115 to read an hall effect joystick which gives 2.56V center then pull it backwards it goes down to 0.5V and push it forwards it goes up to 4.59V and what I'm trying to achieve is using the map function.
So when I push it forwards one map function increases the value to 255 and the other map function is to decrease to 0 and the opposite when I pull it backwards . But the trouble is while sitting in the center and not been moved the map values are different one reads 127 and the other reads 128, Which I thought they should read the same ?
Why do you want to get two values that both represent the joystick position but in different ways?
And what do you intend to do with the values? Maybe representing a 15 bit value as an 8 bit value isnt a good idea - otherwise why not use the ESP32's ADC?
I just thought that if the centre value is 13767 that they should read the same value which is 128.
This is part of a system that uses a Hall effect joystick that has 2 output voltages where 2.5v centre and one side increases and other side decreases, which is used to indicate forwards and backwards plus a fail safe system. There is 8 of them which all goes into a master unit then they convert this gets converted to send the data over canbus.
Reading the canbus data I can see that one of the joystick uses 2 bits which I can see 2x 0X80 has neutral position then when you push it forwards the one goes to 0 and the other goes to FF working through the range depending on how far you push it.
What I want to do is use something like PS3/4 controller using the buttons to select which joystick to use on the system and then use the joystick side on the controller to do the same job. but using an ESP32 to check and get things working first. I'm using a single hall effect joystick at the moment but will swap to the controller once ting are working.
But the joystick on the controller only has a single output so I wanted to use the map function to create the same effect by remotely connecting it to the canbus system sending the same values has the original system.
Hope this makes sense
Because 128(0X80) is the neutral position and it causes an issue if one is out at neutral position because it thinks it’s the joystick is moved and starts to operate, May be I’ll try using the ESP32 ADC set either 12/10 bit plus use a resistor divider means that the voltage is 5 and see if that gets better results
Why do not use the one map function for both values and calculate first value from the map func directly and the second as 256 - first? It will give you a desired result - the centre of the both ranges will be exactly 128.
The only thing you will need to add - a limit the second value against exceeding the 255, say, by simple if condition