HID/examples/HID_Advanced/AdvancedGamepad/AdvancedGamepad.ino

47 lines
1.2 KiB
Arduino
Raw Normal View History

2015-01-02 15:23:27 +00:00
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Advanced Gamepad example
2015-01-11 22:11:43 +00:00
*/
2015-01-02 15:23:27 +00:00
const int pinLed = LED_BUILTIN;
const int pinButton = 2;
// see HID_Reports.h for all data structures
HID_GamepadReport_Data_t Gamepadreport;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Sends a clean report to the host. This is important on any Arduino type.
memset(&Gamepadreport, 0, sizeof(Gamepadreport));
2015-01-02 15:59:33 +00:00
HID_SendReport(HID_REPORTID_GAMEPAD, &Gamepadreport, sizeof(Gamepadreport));
2015-01-02 15:23:27 +00:00
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// This demo is actually made for advanced users to show them how they can write an own report.
// This might be useful for a Gamepad if you want to edit the values direct on your own.
// count with buttons binary
static uint32_t count = 0;
Gamepadreport.whole32[0] = count++;
// move x/y Axis to a new position (16bit)
Gamepadreport.whole16[2] = (random(0xFFFF));
// functions before only set the values
// this writes the report to the host
2015-01-02 15:59:33 +00:00
HID_SendReport(HID_REPORTID_GAMEPAD, &Gamepadreport, sizeof(Gamepadreport));
2015-01-02 15:23:27 +00:00
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}