_Hi guys, I was working on testing a joystick and using Arduino to read the value from the serial port. But when i read the value, it's pretty weird i don't know how to say. The value is not stay in the middle which is about 511 or 512 whatever instead of that, the entire value is all messed up. I'm using board Arduino UNO R3 SMD(not DIP), a KY-023 joystick and a breadboard.
_Here is my code:
int Xpin=A1;
int Ypin=A0;
int Xvalue;
int Yvalue;
int Spin=5;
int Svalue;
void setup() {
// put your setup code here, to run once:
pinMode(Xpin, INPUT);
pinMode(Ypin, INPUT);
pinMode(Spin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Xvalue=analogRead(Xpin);
Yvalue=analogRead(Ypin);
Svalue=digitalRead(Spin);
Serial.print("X value=");
Serial.print(Xvalue);
Serial.print(";");
Serial.print("Y value=");
Serial.print(Yvalue);
Serial.print(";");
Serial.print(Svalue);
Serial.println(";");
delay(1000);
}
_Here is my circuit:
(mod edit)