Created
May 18, 2021 06:53
-
-
Save vsTerminus/82c0b0fe1d34867c6dc6cca95e8427f8 to your computer and use it in GitHub Desktop.
Revisions
-
vsTerminus created this gist
May 18, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ // Ground digital pins 2 and 3 to press joystick buttons 0 and 1 // // Based on the "Simple example application that shows how to // read four Arduino digital pins and map them to the USB Joystick library" // by Matthew Heironimus // 2015-11-20 // // Modified to replace a broken "Mega Shifter" 18-speed shift knob controller // by vsTerminus // 2021-05-18 //-------------------------------------------------------------------- #include <Joystick.h> Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD, 2, 0, // Button count, Hat switch count false, false, false, // No X, Y, or Z false, false, false, // No Rx, Ry, or Rz false, false, // No rudder or throttle false, false, false); // No accelerator, brake, or steering void setup() { // Initialize Button Pins pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); // Initialize Joystick Library Joystick.begin(); } // Last state of the button int lastButtonState[2] = {0,0}; int currentButtonState[2] = {0,0}; void loop() { // Read pin values currentButtonState[0] = digitalRead(2); // Range Select Up presses Button 0 currentButtonState[1] = !digitalRead(3); // Splitter Forward presses Button 1 for (int i = 0; i <= 1; i++) { if (currentButtonState[i] != lastButtonState[i]) { Joystick.setButton(i, currentButtonState[i]); lastButtonState[i] = currentButtonState[i]; } } delay(50); }