Hi folks!
Today I show you my Scania 4-Series Opticruise working in ETS2. In fact, it will work on any Simulator due to the use of an Arduino Leonardo which Windows will recognize as a HID device (keyboard). I programmed Shift up to "Right Shift" and shift down to "Right CTRL" which are the ETS2 default keys for shifting gear!
Have fun!
Arduino Leonardo Code:
#include "Keyboard.h"
#define SHIFTUP_PIN 2
#define SHIFTDOWN_PIN 3
// Works on the Leonardo board
// Build by Jeroen van der Velden
// https://hackaday.io/project/8448-real-scania-truck-home-simulator
static void ShiftUp(void)
{
Keyboard.press(KEY_RIGHT_SHIFT);
}
static void ShiftDown(void)
{
Keyboard.press(KEY_RIGHT_CTRL);
}
void setup(void)
{
Keyboard.begin();
// Set pin to input
pinMode(SHIFTUP_PIN, INPUT);
// Enable pullup resistor
digitalWrite(SHIFTUP_PIN, HIGH);
// Set pin to input
pinMode(SHIFTDOWN_PIN, INPUT);
// Enable pullup resistor
digitalWrite(SHIFTDOWN_PIN, HIGH);
}
void loop(void)
{
static uint8_t shiftUpStateLast = 0;
static uint8_t shiftDownStateLast = 0;
uint8_t shiftState;
shiftState = digitalRead(SHIFTUP_PIN);
if (shiftState != shiftUpStateLast) {
shiftUpStateLast = shiftState;
if (shiftState == 0) {
ShiftUp();
delay(100);
Keyboard.releaseAll();
}
}
shiftState = digitalRead(SHIFTDOWN_PIN);
if (shiftState != shiftDownStateLast) {
shiftDownStateLast = shiftState;
if (shiftState == 0) {
ShiftDown();
delay(100);
Keyboard.releaseAll();
}
}
delay(50);
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.