#define VERT_PIN A0
#define HORZ_PIN A1
#define SEL_PIN 2
void setup() {
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(SEL_PIN, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
int vert = analogRead(VERT_PIN);
int horz = analogRead(HORZ_PIN);
bool selPressed = digitalRead(SEL_PIN) == LOW;
if(vert == 1023)
{
Serial.println("top");
}
else if(vert == 0)
{
Serial.println("bottom");
}
if(horz == 1023){
Serial.println("left");
}
else if(horz == 0)
{
Serial.println("right");
}
if(vert == 512 && horz == 512 )
{
Serial.println("center");
}
// horz goes from 0 (right) to 1023 (left)
// vert goes from 0 (bottom) to 1023 (top)
// selPressed is true is the joystick is pressed
}