
89Chapter 5: The Joy of Joysticks
GND pin of our Arduino. Finally, the SEL, SW, or
BTN for the internal push-button on the joystick
will be connected to digital pin 4. With that, we
have completed all our basic connections.
STEP 2
WRITING A SIMPLE JOYSTICK DATA SKETCH
int joyX;
int joyY;
void setup() {
Serial.begin(9600);
}
void loop() {
joyX = analogRead(A0);
joyY = analogRead(A1);
Serial.print("Joystick X Value: ");
Serial.print(joyX);
Serial.print(" Joystick Y Value: ");
Serial.println(joyY);
delay(10);
}
Once your code has been uploaded onto your
Arduino, open the Serial Monitor to view the
joystick data (Figure
5-4
). As you move the
joystick, you should ...