Close

Arduino Code

A project log for Logitech G27 Compatibility Tool

Play old PC games with sequential shifting with the Logitech G27 with full support for the H-Shifter

leon-batailleLeon Bataille 11/25/2015 at 10:290 Comments

For all of you who want to rebuild this at home.

This sketch controls a 7-segment display as a gear indicator and simulates a keypress when corresponding data is being received through the Arduino's serial port.

The display is able to show: r (reverse), n (neutral), 1, 2, 3, 4, 5, 6

// Eine 7-Segment Anzeige ansteuern
//
// Matthias Busse Version 1.0 vom 30.11.2014

// 7-Segment a-f und der Punk h
//  -a-
// f   b
//  -g-
// e   c
//  -d-   h

// a > D2
// b > D3
// c > D4
// d > D5
// e > D6
// f > D7
// g > D8
// h > D9 

int j=1;

//            R           N           1          2          3          4          5          6          7          8          9          10        11        12
//byte z[14]={B00001010, B00101010, B01100000, B11011010, B11110010, B01100110, B10110110, B10111110, B11100000, B11111110, B11110110, B11111101, B01100001, B11011011}; 

//            R           N           1          2          3          4          5          6
byte z[8]={B00001010, B00101010, B01100000, B11011010, B11110010, B01100110, B10110110, B10111110};

void setup() {
  for (int i=2; i <= 9; i++) // 2-9 sind Ausgänge
    pinMode(i,OUTPUT);
  
  // open the serial port:
  Serial.begin(9600);
  // initialize control over the keyboard:
  Keyboard.begin();
  
}

void loop() {
  segmente(z[j]);
  // check for incoming serial data:
  if (Serial.available() > 0) {
    // read incoming serial data:
    char inChar = Serial.read();
    
    // Type the next ASCII value from what you received:
    if ((inChar == 'p') && (j < 7)) {
      Keyboard.press(0x81);
      delay(100);
      Keyboard.releaseAll();
      j++;
      segmente(z[j]);
      }
      
    if ((inChar == 'm') && (j > 0)) {
      Keyboard.press(0x80);
      delay(100);
      Keyboard.releaseAll();
      j--;
      segmente(z[j]);
      } 

  }
}

void segmente(byte n) {
// alle 7 Segmente ansteuern

  for(int k=2; k <= 9; k++) {
    if((n & B10000000) > 0)
      digitalWrite(k, HIGH);
    else 
      digitalWrite(k, LOW);
    n = n << 1;
  }  
}

Discussions