Close

ACC / EDC Cruise Control Part 3

A project log for Real Scania Truck Home Simulator

The Scrapyard and Arduino make a great combination!

jeroen-van-der-veldenJeroen van der Velden 02/21/2016 at 12:110 Comments

I made a video for the progress on the Cruise Control. Unfortunately its not finished yet, I still need to find the right code.

Code:

// 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:
  Serial.begin(9600);
}

// 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:
  Serial.println(analogValue);
  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");
   delay(1);
  }
  else
  if (analogValue > 950 && analogValue < 965)
  {
   //ACC is in the ON Pos
   Serial.print("ACC ON");
   delay(1);
  }
   else
   if (analogValue > 985 && analogValue < 995)
  {
   //ACC is in the ON Pos and RET is Pressed
   Serial.print("ACC ON+RET");
   delay(1);
  }
  else
  if (analogValue > 1000 && analogValue < 1011)
  {
   //ACC is in the ON Pos and RES is Pressed
   Serial.print("ACC ON+RES");
   delay(1);
  }
   else
   if (analogValue > 1012 && analogValue < 1025)
  {
   //ACC is in the ON Pos and ACC is Pressed
   Serial.print("ACC ON+ACC");
   delay(1);
  }
}

// Jeroen van der Velden
// https://hackaday.io/project/8448-real-dashboard-truck-simulator
What I need:

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.

Discussions