int x = A0; //Analog Pin for X Position
int y = A1; //Analog Pin for Y Position
int SW = 7; //Digital Pin for Button
//Store State Variables
int xPosition = 0;
int yPosition = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;
void setup() {
Serial.begin(9600);
pinMode(x, INPUT);
pinMode(y, INPUT);
pinMode(SW, INPUT_PULLUP);
}
void loop() {
//Read Data
xPosition = analogRead(x);
yPosition = analogRead(y);
SW_state = digitalRead(SW);
mapX = map(xPosition, 0, 1023, -512, 512);
mapY = map(yPosition, 0, 1023, -512, 512);
//Print Data in Serial Monitor
Serial.print("X: ");
Serial.print(mapX);
Serial.print(" | Y: ");
Serial.print(mapY);
Serial.print(" | Button: ");
Serial.println(SW_state);
delay(100);
}