Hi All ~ I've been following various sites/forums/guides and adding my own input to make my Logitech G29 Shifter display it's gear on a home built 7-segment display. Tested and confirmed the LED segments work on their own. I put the code I made into an Arduino Leonardo and I got it all to work EXCEPT that I can't get gears 1, 3, and 5 to light up their corresponding parts of the 7-segment display. The 2, 4, 6, and Reverse all light up their parts on the 7-segment display. I'm using Windows 11 Home on an Acer laptop so I opened the game controller section of Windows and confirmed that the computer is reading all of the gears (1 to 6 and reverse) so I know it's not an issue with the actual Logitech G29 Shifter. I'm BRAND new to Arduino and I'm trying to teach myself but this is going to be a gift for my son's birthday next week and I'm just stuck. Can ya'll take a look at the code and let me know. Thank you in advance! Best, Alan, RN
//Logitech Driving Force Shifter USB Adapter
//By Armandoiglesias 2018
//Based on Jason Duncan functionreturnfunction Project
//Video tutorial https://www.youtube.com/watch?v=dLpWEu8kCec
//Use Arduino Leonardo
//Install Joystick Library
//Attribution-NonCommercial-NoDerivatives 4.0 International
#include <Joystick.h>
// Create the Joystick
Joystick_ Joystick;
// H-shifter mode analog axis thresholds
#define HS_XAXIS_12 600 //default 390//400
#define HS_XAXIS_56 500 //default 680//500
#define HS_YAXIS_135 800 //default 775//800
#define HS_YAXIS_246 150 //default 425//300
// Sequential shifter mode analog axis thresholds
//#define SS_UPSHIFT_BEGIN 670
//#define SS_UPSHIFT_END 600
//#define SS_DOWNSHIFT_BEGIN 430
//#define SS_DOWNSHIFT_END 500
// Handbrake mode analog axis limits
//#define HB_MAXIMUM 530
//#define HB_MINIMUM 400
//#define HB_RANGE (HB_MAXIMUM-HB_MINIMUM)
// Digital inputs definitions
#define DI_REVERSE 1
#define DI_MODE 3
#define DI_RED_CENTERRIGHT 4
#define DI_RED_CENTERLEFT 5
#define DI_RED_RIGHT 6
#define DI_RED_LEFT 7
#define DI_BLACK_TOP 8
#define DI_BLACK_RIGHT 9
#define DI_BLACK_LEFT 10
#define DI_BLACK_BOTTOM 11
#define DI_DPAD_RIGHT 12
#define DI_DPAD_LEFT 13
#define DI_DPAD_BOTTOM 14
#define DI_DPAD_TOP 15
// Shifter state
#define DOWN_SHIFT -1
#define NO_SHIFT 0
#define UP_SHIFT 1
// Shifter mode
#define SHIFTER_MODE 0
#define HANDBRAKE_MODE 1
// LED blink counter
int led = 0;
// Shifter state
int shift = NO_SHIFT;
// Handbrake mode
int mode = SHIFTER_MODE;
int b[16];
int gear = 0; // Default value is neutral
// Constant that maps the phyical pin to the joystick button.
const int pinToButtonMap = 9;
//AJM Code
int segA = 3;
int segB = 5;
int segC = 6;
int segD = 10;
int segE = 11;
int segF = 12;
int segG = 9;
int _gear_ = 0;
void firstgear() {
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
}
void secondgear() {
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
}
void thirdgear() {
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
}
void fourthgear() {
digitalWrite(segA, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
}
void fifthgear() {
digitalWrite(segA, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segE, HIGH);
}
void sixthgear() {
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segE, LOW);
digitalWrite(segD, LOW);
digitalWrite(segC, LOW);
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
}
void reverse() {
digitalWrite(segE, LOW);
digitalWrite(segG, LOW);
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segF, HIGH);
}
void neutral() {
if (_gear_ == 0 || gear == 0) { //Neutral
digitalWrite(segE, LOW);
digitalWrite(segG, LOW);
digitalWrite(segC, LOW);
}
}
void setup() {
// G29 shifter analog inputs configuration
pinMode(A2, INPUT_PULLUP); // was 0 // X axis
pinMode(A4, INPUT_PULLUP); // was 2 // Y axis
pinMode(2, INPUT);
//AJM Code
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
for (int i = 0; i < 16; i++) b[i] = 0;
b[DI_MODE] = 0;
// Initialize Joystick Library
Joystick.begin();
}
// Last state of the button
int lastButtonState = 0;
void loop() {
int x = analogRead(2); //was 0 // X axis
int y = analogRead(4); //was 2 // Y axis
int _isreverse = digitalRead(2);
int _gear_ = 0;
if (_isreverse == 1) {
_gear_ = 8;
b[DI_REVERSE] = 1;
reverse();
} else {
if (b[DI_MODE] == 0) // H-shifter mode?
{
if (x < HS_XAXIS_12) // Shifter on the left?
{
if (y > HS_YAXIS_135) _gear_ = 1; // 1st gear
firstgear();
if (y < HS_YAXIS_246) _gear_ = 2; // 2nd gear
secondgear();
} else if (x > HS_XAXIS_56) // Shifter on the right?
{
if (y > HS_YAXIS_135) _gear_ = 5; // 5th gear
fifthgear();
if (y < HS_YAXIS_246) _gear_ = 6; // 6th gear
sixthgear();
} else // Shifter is in the middle
{
if (y > HS_YAXIS_135) _gear_ = 3; // 3rd gear
thirdgear();
if (y < HS_YAXIS_246) _gear_ = 4; // 4th gear
fourthgear();
}
}
}
if (gear != 6) {
b[DI_REVERSE] = 0; // Reverse gear is allowed only on 6th gear position
//reverse();
}
if (_gear_ != gear) {
gear = _gear_;
desactivar();
Joystick.setButton(gear - 1, HIGH);
neutral();
}
delay(100);
}
void desactivar() {
// Depress virtual button for current gear
for (int i = 0; i <= 10; i++) Joystick.setButton(i, LOW);
}