Home
About
Blog
Media Gallery

DJ Truck Dash


The code for my custom truck sim dash/button panel. Real auto switches connected to an Arduino Micro board.

MHeironimus/ArduinoJoystickLibrary
Media Gallery

Arduino IDE
#include <Joystick.h>

int AntallKnapper = 17;

Joystick_ Joystick(
  0x03,   // hidReportId
  0x04,   // joystickType
  AntallKnapper,     // buttonCount
  0,      // hatSwitchCount
  false,  // includeXAxis
  false,  // includeYAxis 
  false,  // includeZAxis
  false,  // includeRxAxis
  false,  // includeRyAxis
  false,  // includeRzAxis
  false,  // includeRudder
  false,  // includeThrottle
  false,  // includeAccelerator
  false,  // includeBrake
  false   // includeSteering
);

void setup() {
  // Alle brytere unntatt START holdes i HIGH modus. 
  // Siden arduino har intern pullup resistor, er det praktisk å gjøre det slik.
  pinMode(2, INPUT_PULLUP); // JAKE
  pinMode(3, INPUT_PULLUP); // JAKE OPP
  pinMode(4, INPUT_PULLUP); // JAKE NED
  pinMode(5, INPUT_PULLUP); // PARK
  pinMode(6, INPUT_PULLUP); // TRAILER
  pinMode(7, INPUT_PULLUP); // LIGHTS
  pinMode(8, INPUT_PULLUP); // HIGH BEAM
  pinMode(9, INPUT_PULLUP); // BEACON
  pinMode(10, INPUT_PULLUP); // HAZARDS
  pinMode(11, INPUT_PULLUP); // LIFT AXLE TRACTOR
  pinMode(12, INPUT_PULLUP); // LIFT AXLE TRAILER
  pinMode(A5, INPUT_PULLUP); // LOCK DIFF
  pinMode(A4, INPUT_PULLUP); // VINDU H NED
  pinMode(A3, INPUT_PULLUP); // VINDU H OPP
  pinMode(A2, INPUT_PULLUP); // VINDU L NED
  pinMode(A1, INPUT_PULLUP); // VINDU L OPP

  // A0 er koblet til GND via en 10K resistor for pulldown slik at den holder seg i LOW status.
  // Da kan vi koble +5V til bryter slik at den lyser rødt, og benytte at A0 da går i HIGH modus.
  pinMode(A0, INPUT); // START
  
  Joystick.begin();
}

void loop() {

  // START.
  // Denne har LOW når den er av, så vi leser vanlig.
  Joystick.setButton(0, digitalRead(A0));
  
  // Alle de andre.
  // Disse har HIGH når de er av, vi leser derfor !(motsatt).
  Joystick.setButton(1, !digitalRead(2));
  Joystick.setButton(2, !digitalRead(3));
  Joystick.setButton(3, !digitalRead(4));
  Joystick.setButton(4, !digitalRead(5));
  Joystick.setButton(5, !digitalRead(6));
  Joystick.setButton(6, !digitalRead(7));
  Joystick.setButton(7, !digitalRead(8));
  Joystick.setButton(8, !digitalRead(9));
  Joystick.setButton(9, !digitalRead(10));
  Joystick.setButton(10, !digitalRead(11));
  Joystick.setButton(11, !digitalRead(12));
  Joystick.setButton(12, !digitalRead(A1));
  Joystick.setButton(13, !digitalRead(A2));
  Joystick.setButton(14, !digitalRead(A3));
  Joystick.setButton(15, !digitalRead(A4));
  Joystick.setButton(16, !digitalRead(A5));
  
  delay(50);
}


Original Post: Feb 2nd, '22 18:31 CET.
Updated: Feb 2nd, '22 18:33 CET.

Tags: Arduino