Two potentiometers joystick question

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);
 }

Thanks

combine point of the axes.

What do you mean?

I don't know the math in order to have the combine point of the axes

What do you want to get from the combination of the value from each axis ?

UKHeliBob:
What do you want to get from the combination of the value from each axis ?

I would like to have only one data in a given moment
as it usually with joysticks, isn't it ?

R_Gol:
I would like to have only one data in a given moment
as it usually with joysticks, isn't it ?

I wonder: if you had say 2x servos running ala the sweep edit: knob sketch, then no you would want them separate.

If you only want "one data" then it's up to you decide what the relationship between x, y and that "one data" needs to be.

You could use Pythagorus I suppose, to get the hypotenuse distance; but it's up to you to define what you need.

blomcrestlight:
I wonder: if you had say 2x servos running ala the sweep sketch, then no you would want them separate.

If you only want "one data" then it's up to you decide what the relationship between x, y and that "one data" needs to be.

You could use Pythagorus I suppose, to get the hypotenuse distance; but it's up to you to define what you need.

Ok got you,
I think I got confused. X-axis data and Y-axis data separated is good for me. my mistake!

Cool....

But in general it should be feasible to define z=f(x,y) when one day you need that, but what "f" is up to you.

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

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.

Steve

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.

Steve

Yes calibrate :slight_smile:
Thanks for your advice!

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.

bluejets:
In the link there appears to be an adjustment on the side for each pot.

It looks like it to me too

Oh great! did not notice it