Home

Awesome

ArduinoGamepad

A GamePad HID library for Arduino Pro Micro/Leonardo (ATMega32u4) This library works only on Arduino IDE 1.6.6 or higher!

How to install

Create a new directory named "Gamepad" in Documents > Arduino > libraries, and copy all files from repository into that directory

How to make a Gamepad

http://www.instructables.com/id/Arduino-LeonardoMicroATMega32u4-As-GamepadGame-Con/

Small example

//Including a library
#include <Gamepad.h>

//Initializing a Gamepad
Gamepad gp;

int buttonIndex = 0;
bool setState = true;

void setup() {

}

void loop() {
  gp.setButtonState(buttonIndex++, setState);
  if(buttonIndex == 16)
  {
    setState = !setState; //negate the value
    buttonIndex = 0;
  }
  delay(500);
}

How to test gamepad

Functions reference

Gamepad(bool useZRx = false)

Initializing a USB HID Descriptor

sendUpdate()

Sending a update report, its not needed to use, its executed automatically

setButtonState(uint8_t button, bool state)

Setting a Button State

setLeftXaxis(uint8_t axis)

Setting an "axis" for Left Thumbstick X Axis

setLeftYaxis(uint8_t axis)

Setting an "axis" for Left Thumbstick Y Axis

setRightXaxis(uint8_t axis)

Setting an "axis" for Right Thumbstick X Axis

setRightYaxis(uint8_t axis)

Setting an "axis" for Right Thumbstick Y Axis