The EventJoystick class contains two EventAnalog inputs configured as a joystick.
#include <EventJoystick.h>
// Create an EventJoystick input
EventJoystick myJoystick(A0, A1);
// Create a callback handler function
void onJoystickEvent(InputEventType et, EventJoystick& ej) {
Serial.print("Joystick event fired. X position is: ");
Serial.print(ej.x.position());
Serial.print(" Y position is: ");
Serial.println(ej.y.position());
}
void setup() {
Serial.begin(9600);
myJoystick.begin();
// Link the joystick's callback to function defined above
myJoystick.setCallback(onJoystickEvent);
myJoystick.setStartValues();
}
void loop() {
// Call 'update' for every EventJoystick
myJoystick.update();
}See example Joystick.ino for a slightly more detailed sketch.
See EventJoystick's Doxygen generated API documentation for more information.