/********************************************** * joystick ardunio uno * Gnd----------------GND * +5V----------------5V * VRx----------------A0 * VRy----------------A1 * SW-----------------D3 * *********************************************/ #define BUAD_RATE 9600 const int SW=3; int FirstShotX , FirstShotY; void setup() { pinMode(SW, INPUT); Serial.begin(BUAD_RATE); FirstShotX = 0; FirstShotY = 0; } void loop() { int z=digitalRead(SW); if(z==0) Serial.println("--------->Z"); int sensorValue = analogRead(A0); if(FirstShotX == 0) { FirstShotX = sensorValue; Serial.print("FirstShotX = "); Serial.println(FirstShotX); } Serial.print("X = "); Serial.println(sensorValue - FirstShotX); sensorValue = analogRead(A1); if(FirstShotY == 0) { FirstShotY = sensorValue; Serial.print("FirstShotY = "); Serial.println(FirstShotY); } Serial.print("Y = "); Serial.println(sensorValue - FirstShotY); delay(200); }