/* Xbox style controller featuring two joysticks, 17 buttons, and a toggle switch to allow the joystick to act as a mouse. This code was based off the Teensy USB Joystick example code as well as Gadget Reboot's USB Mouse code https://www.pjrc.com/teensy/td_joystick.html https://github.com/GadgetReboot/Arduino/tree/master/Teensy/USB_HID_Mouse */ const int numButtons = 27; const int ledPin = LED_BUILTIN; const int mouseToggleSwitch = 17; const int leftClick = 2; const int rightClick = 3; const int xAxis = A0; const int yAxis = A1; // parameters for reading the joystick: int range = 12; // output range of X or Y movement int threshold = range / 4; // resting threshold int center = range / 2; // resting position value bool mouseEnabled = false; int lastSwitchState = HIGH; void setup() { pinMode(ledPin, OUTPUT); Joystick.useManualSend(true); for (int i=0; i