Hello i have trouble mapping correctly the values from 2 joysticks.
I use the ADS1115 to read all the analog outputs from the joysticks but i cant get the value right.
I need to map the joysticks in a way to control servo motor angles.
The problem is that i cannot get a stable reading due to the 16 bit resolution and cannot find a way to work around it. I do not need the 16 bit resolution only the I2C interface of the ADS1115.
The range of the output varies between the joystick axis
for example i made a sketch to find the highs and lows of each axis and the results are
HIGH LOW
X1 23564 15
Y1 23564 1818
X2 23504 98
Y2 23510 19
When mapping the values and the joysticks are idle i get the following angles
X1 87
Y1 80-81 (it fluctuates constantly)
X2 86-87 (it fluctuates constantly)
Y2 93
Code :
#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads;
int adc0, adc1, adc2, adc3; // ADC Readings
int X1angle,Y1angle,X2angle,Y2angle; //Joystick Angle Variables
void setup()
{
ads.begin();
}
void loop()
{
adc0=ads.readADC_SingleEnded(0);
adc1=ads.readADC_SingleEnded(1);
adc2=ads.readADC_SingleEnded(2);
adc3=ads.readADC_SingleEnded(3);
X1angle=map(adc2,15,23564,0,180);
Y1angle=map(adc3,1818,23564,0,180);
X2angle=map(adc0,98,23504,0,180);
Y2angle=map(adc1,19,23510,0,180);
}
Edit : Forgot to mention that the code posted here is just for the adc in the project the whole sketch is large and none of the other bits of code relate to the adc.