Skip to content

Instantly share code, notes, and snippets.

@vsTerminus
Created May 18, 2021 06:53
Show Gist options
  • Save vsTerminus/82c0b0fe1d34867c6dc6cca95e8427f8 to your computer and use it in GitHub Desktop.
Save vsTerminus/82c0b0fe1d34867c6dc6cca95e8427f8 to your computer and use it in GitHub Desktop.
Replacement Arduino program for TechAffliction Mega Shifter
// 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);
}
@GeneralMarkusParkus
Copy link

Had this same USB issue and replaced the board but had no idea of the code to use with the hall sensors.
This totally saved the day!

Thanks you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment