[CODE lang="cpp" title="H Vites"]// 8 button gamepad, switches on digital pins 2-10
#include <Joystick.h>
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
9, 0, // Button Count, Hat Switch Count
false, false, false, // No X, Y, Z Axis
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);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
// Initialize Joystick Library
Joystick.begin();
}
// Last state of the buttons
int lastButtonState[9] = {0,0,0,0,0,0,0,0,0};
void loop() {
// Read pin values
for (int index = 0; index < 9; index++)
{
int currentButtonState = !digitalRead(index + 2);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}
delay(10);
}
`[/CODE]
Here is a simple H pattern shifter for racing and trucking simulators. Also includes an optional handbrake.https://www.youtube.com/watch?v=Px6vMj98-FQHardware needed:M3 screws, about 15 mm, about 20 piecesArduino Micro or Leonardo (or other gamepad device)A rubber bandMicroswitches with long...
www.thingiverse.com