Need help with code (Boolean for HID)

Hi all, I have a challenge I cant solve, I need your help!

I have a truck cruise control lever I want to connect to an Arduino Leonardo and have it act like a keyboard (HID).

The lever has only two wires so I need to stick with 2-wires. The lever has 3 push buttons and one toggle switch. I do know the input voltage is 5 volt and every button has its own resistor causing different voltages to come out when used. This way the car computer knows what has been pressed.

I have 3 switches:

1: Acc (Cruise Control Accelerate speed)
2: Ret (Cruise Control Retrieve speed)
3: Res (Cruise Control Resume from last speed)

I have one toggle Switch:

Cruisecontrol ON/OFF

I want the ON/OFF to toggle a keyboard character “C” when used.
I want button 1 to send a “7”
I want button 2 to send an “8”
I want button 3 to send a “9”

The code should pause after each change (no loop). The 10k Restistor is a pull-up resistor for debounce.
There is an Arduino Ohm meter tutorial so that might be a start.



Code video click here!

Code unfinished:

// Arduino Leonardo Rev3.0
// This code is for all Scania 4-Series
// ACC HID control for ETS2
void setup() {
// initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int analogValue = analogRead(A0);
// print out the value you read:
delay(100); // delay in between reads for stability
if (analogValue > 870 && analogValue < 890) // read the analogue input into variable analogValue
//ACC is in the OFF Pos
Serial.print(“ACC OFF”);
if (analogValue > 950 && analogValue < 965)
//ACC is in the ON Pos
Serial.print(“ACC ON”);
if (analogValue > 985 && analogValue < 995)
//ACC is in the ON Pos and RET is Pressed
Serial.print(“ACC ON+RET”);
if (analogValue > 1000 && analogValue < 1011)
//ACC is in the ON Pos and RES is Pressed
Serial.print(“ACC ON+RES”);
if (analogValue > 1012 && analogValue < 1025)
//ACC is in the ON Pos and ACC is Pressed
Serial.print(“ACC ON+ACC”);

// Jeroen van der Velden

Are you sure it is voltage and not PWM? Different PWMs can sometimes appear on a voltage meter as different voltages.


Hi Steve, please check my code and video attached!

Found help elsewhere! Thanks!