Wrong joystick values

Hey, my joystick does not return the right values.
at first the values of the X axis were right, but the Y started at resting position 0 (instead of 512). The rangr og Y was0-512. not even less then 0.

tried to calibrate it' and now the whole joystick returns odd values(both X and Y).

any ideas?
(in my joystick, the X is connected to A2 and Y to A1)

thats my code:

int xpin = A2;
int ypin = A1;
int xval;
int yval=512;

void setup() {
Serial.begin(9600);
pinMode(xpin , INPUT);
pinMode(ypin , OUTPUT);
}

void loop() { 
xval=analogRead(xpin);
yval = analogRead(ypin);

delay(200);
Serial.print("X: ");
Serial.print(xval);
Serial.print(" y: ");
Serial.println(yval);

}

i using the calibration from here:

Are you sure. ???

Try :
pinMode(xpin , INPUT);
pinMode(ypin , INPUT);

thank you!
tried everything and it was so simple.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.