Giter Site home page Giter Site logo

arduinogamepad's Introduction

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

  • Just try a game what supports a normal GamePad (not X360, if you want to play game whats support only X360, use X360CE)
  • Or use a Windows Devices "Tester" (where is option to calibrate a GamePad, but I recommending a Arduinos calibration in example project): Go to Control Panel > Devices and Printers and search your device (for me its a Arduino Leonardo) > Right click > Settings of game device > Properties > Test

Functions reference

Gamepad(bool useZRx = false)

Initializing a USB HID Descriptor

  • boolean useZRx (default false): Z is used to represent the right stick’s X axis, Rx is used to represent the right stick’s Y axis. This doesn’t make sense but this is how most existing USB game pads work. I have tested this using Battlefield Bad Company 2, it works. SOURCE

sendUpdate()

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

setButtonState(uint8_t button, bool state)

Setting a Button State

  • uint8_t button - Number of button (0 - 15), Button #1 is 0, Button #2 is 1 etc...
  • bool state - true is pressed, false is released

setLeftXaxis(uint8_t axis)

Setting an "axis" for Left Thumbstick X Axis

  • uint8_t axis - a value from -127 to 127, when 0 means center (you must format a values from real Thumbsticks to this ranges)

setLeftYaxis(uint8_t axis)

Setting an "axis" for Left Thumbstick Y Axis

  • uint8_t axis - a value from -127 to 127, when 0 means center (you must format a values from real Thumbsticks to this ranges)

setRightXaxis(uint8_t axis)

Setting an "axis" for Right Thumbstick X Axis

  • uint8_t axis - a value from -127 to 127, when 0 means center (you must format a values from real Thumbsticks to this ranges)

setRightYaxis(uint8_t axis)

Setting an "axis" for Right Thumbstick Y Axis

  • uint8_t axis - a value from -127 to 127, when 0 means center (you must format a values from real Thumbsticks to this ranges)

arduinogamepad's People

Contributors

gamelaster avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.