int VRx = A0; // X axis pin established
int VRy = A1; // Y axis pin established
int SW = 0; // Switch pin established
int xPosition = 0; // Establishing relevant variables
int yPosition = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;
int Oldx = 1;
int Oldy = 1;
int Oldsw = 1;
void setup() {
Serial.begin(9600); // Serial output for test established
pinMode(VRx, INPUT);
pinMode(VRy, INPUT);
pinMode(SW, INPUT_PULLUP);
}
void loop() {
xPosition = analogRead(VRx);
yPosition = analogRead(VRy);
SW_state = digitalRead(SW);
if (xPosition != Oldx){
Oldx = xPosition;
mapX = map(xPosition, 0, 1023, -512, 512);
Serial.print("X: ");
Serial.println(mapX);
}
if (yPosition != Oldy){
Oldy = yPosition;
mapY = map(yPosition, 0, 1023, -512, 512);
Serial.print("Y: ");
Serial.println(mapY);
}
if (SW_state != Oldsw){
Oldsw = SW_state;
Serial.print("Button: ");
Serial.println(SW_state);
}
delay(100);
}