#define JOYSTICK_X A0
#define JOYSTICK_Y A1
#define JOYSTICK_BUTTON 2
int pinA = 2; //Declaring variables for the pins
int pinB = 4;
int pinC = 6;
int pinD = 8;
void setup() {
pinMode(pinA, INPUT); //Setting up the internal pull-ups resistors
pinMode(pinB, INPUT); //and also setting the pins to inputs.
pinMode(pinC, INPUT);
pinMode(pinD, INPUT);
pinMode(JOYSTICK_BUTTON, INPUT_PULLUP);
Serial.begin (9600);
}
void loop() {
if (digitalRead(pinA) == HIGH) //Checking if the first switch has been pressed
{
Serial.write('W'); //Sending the "W" character
delay(500);
}
if (digitalRead(pinB) == HIGH) //Checking if the second switch has been pressed
{
Serial.write('S'); //Sending the "S" character
delay(500);
}
if (digitalRead(pinC) == HIGH) //Checking if the third switch has been pressed
{
Serial.write('A'); //Sending the "A" character
delay(500);
}
if (digitalRead(pinD) == HIGH) //Checking if the fourth switch has been pressed
{
Serial.write('D'); //Sending the "D" character
delay(500);
}
int x = analogRead(JOYSTICK_X);
int y = analogRead(JOYSTICK_Y);
int button = !digitalRead(JOYSTICK_BUTTON);
Serial.print("X: " + String(x));
Serial.print(",\tY:" + String(y));
Serial.println(",\tP: " + String(button));
delay(100);
}