
/*
  EasyJoystick - getState example

  Demonstrates how to use getState() with changed() to detect when the
  joystick position changes, rather than continuously reading the same state.

  Only prints output when the joystick moves to a new position.

  The raw state value is printed first, followed by a readable label.
  
  Wiring:
    VRx -> A1
    VRy -> A2
    VCC -> 5V
    GND -> GND
	
  Note:
    joystick.begin(xPin, yPin, flipX, flipY)
    - xPin, yPin must be analog pins
    - flipX/flipY invert directions if needed

*/

#include <EasyJoystick.h>

EasyJoystick joystick;

void setup() {
  joystick.begin(A1, A2, true, true);
  Serial.begin(115200);
}

void loop() {
  joystick.loop();
  if (joystick.changed()) {
    Serial.print(joystick.getState());
    Serial.print(" = ");
    if (joystick.getState() == EasyJoystick::NONE) {
      Serial.println("none");
    } else if (joystick.getState() == EasyJoystick::MIDDLE) {
      Serial.println("middle");
    } else if (joystick.getState() == EasyJoystick::UP) {
      Serial.println("up");
    } else if (joystick.getState() == EasyJoystick::DOWN) {
      Serial.println("down");
    } else if (joystick.getState() == EasyJoystick::LEFT) {
      Serial.println("left");
    } else if (joystick.getState() == EasyJoystick::RIGHT) {
      Serial.println("right");
    }
  }
}
