Hi there,
I have this joystick with two potentiometers - 1 for the x axis and the other for the y axis.
I manage to get in the serial port the data from each potentiometer but I don’t know the math in order to have the combine point of the axes.
Can someone help me with that ?
this is the code I’m using right-now:
#define knob1 A0
#define knob2 A1
#define ledPin 13
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// reads the value of the variable resistor
int value1 = analogRead(knob1);
value1 = map(value1, 0, 1023, 0, 510);
Serial.print("knob1: ");
Serial.println(value1);
delay(50);
int value2 = analogRead(knob2);
value2 = map(value2, 0, 1023, 0, 510);
Serial.print("knob2: ");
Serial.println(value2);
}
btw - I notice that in the rest position (the middle position of the joystick) the values are: x - 536 and y- 483. I understand that values supposed to be both 512. Is there anyway to collaborate it ?
I think you mean "calibrate". You might be able to physically move the potentiometers round slightly. Or if the values really are CONSISTENTLY 536 and 483 you could always just use offsets of -24 and +29 when you read them. But those joysticks don't usually centre very reliably so the values might fluctuate quite a bit anyway.
slipstick:
I think you mean "calibrate". You might be able to physically move the potentiometers round slightly. Or if the values really are CONSISTENTLY 536 and 483 you could always just use offsets of -24 and +29 when you read them. But those joysticks don't usually centre very reliably so the values might fluctuate quite a bit anyway.
R_Gol:
btw - I notice that in the rest position (the middle position of the joystick) the values are: x - 536 and y- 483. I understand that values supposed to be both 512. Is there anyway to collaborate it ?
Thanks
In the link there appears to be an adjustment on the side for each pot.