const int SW_pin = 2; // digital pin connected to switch output
const int Y_pin = A0; // analog pin connected to X output
const int X_pin = A1; // analog pin connected to Y output
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
}
void loop() {
int x = map(analogRead(X_pin), 0, 1023, 1, -1);
int y = map(analogRead(Y_pin), 0, 1023, -1, 1);
if(x != 0 || y != 0){
if(y == 1 && x == 0) Serial.println("UP");
else if(y == -1 && x == 0) Serial.println("DOWN");
else if(x == -1 && y == 0) Serial.println("LEFT");
else if(x == 1 && y == 0) Serial.println("RIGHT");
}
/*
if((x < 500 || x > 512) || (y < 500 || y > 512)){
if (x > 512 && y < 512) Serial.println("UP");
else if
}
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
*/
delay(1000);
}