Liam S
LiamS1 follower
Follow
LiamS
LiamS
|
Image 1 of 4
Sim Racing Sequential shifter 3d model
LiamS
LiamS
|
Image 1 of 4
Sim Racing Sequential shifter 3d model
Sim Racing Sequential shifter 3d model
Sim Racing Sequential shifter 3d model
Sim Racing Sequential shifter 3d model
Sim Racing Sequential shifter 3d model

Sim Racing Sequential shifter

Parts list (does not include mounting hardware)

code below will work for buttons soldered to GPIO 1,2,3,4,5,6,7,8,9 and for a joystick on GPIO 27 and 28 if you want to repurpose it or add more functions.

#include <PicoGamepad.h>

PicoGamepad gamepad;

// 16 bit integer for holding input values int xVal; int yVal;

void setup() {
Serial.begin(115200);

pinMode(LED_BUILTIN, OUTPUT);

// X Potentiometer on pin 27 pinMode(27, INPUT); // Y Potentiometer on pin 28 pinMode(28, INPUT);

// Buttons on GPIO 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 pinMode(0, INPUT_PULLUP); pinMode(1, INPUT_PULLUP); pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); pinMode(5, INPUT_PULLUP); pinMode(6, INPUT_PULLUP); // Add GPIO 6 as input with internal pull-up resistor pinMode(7, INPUT_PULLUP); // Add GPIO 7 as input with internal pull-up resistor pinMode(8, INPUT_PULLUP); // Add GPIO 8 as input with internal pull-up resistor pinMode(9, INPUT_PULLUP); // Add GPIO 9 as input with internal pull-up resistor }

void loop() {

// Get input value from Pico analog pin for X axis xVal = analogRead(27); // Map analog 0-1023 value from pin to max HID range -32767 - 32767 xVal = map(xVal, 0, 1023, -32767, 32767); // Send value to HID object gamepad.SetX(xVal);

// Repeat with Y pin for Y axis yVal = analogRead(28); yVal = map(yVal, 0, 1023, -32767, 32767); gamepad.SetY(yVal);

// Set buttons: 0 = GPIO 0, 1 = GPIO 1, 2 = GPIO 2, 3 = GPIO 3, 4 = GPIO 4, 5 = GPIO 5 // 6 = GPIO 6, 7 = GPIO 7, 8 = GPIO 8, 9 = GPIO 9 gamepad.SetButton(0, !digitalRead(0)); gamepad.SetButton(1, !digitalRead(1)); gamepad.SetButton(2, !digitalRead(2)); gamepad.SetButton(3, !digitalRead(3)); gamepad.SetButton(4, !digitalRead(4)); gamepad.SetButton(5, !digitalRead(5)); gamepad.SetButton(6, !digitalRead(6)); // Set button 6 based on GPIO 6 state gamepad.SetButton(7, !digitalRead(7)); // Set button 7 based on GPIO 7 state gamepad.SetButton(8, !digitalRead(8)); // Set button 8 based on GPIO 8 state gamepad.SetButton(9, !digitalRead(9)); // Set button 9 based on GPIO 9 state

// Send all inputs via HID gamepad.send_update();

// Flash the LED just for fun digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); delay(100); }


Discussions

Sim Racing Sequential shifter

4 downloads · 1 year ago in  and 
Liam S
LiamS1 follower
Follow