Close

Inputs Part 1 (Pro Micro)

A project log for Real Scania Truck Home Simulator

The Scrapyard and Arduino make a great combination!

jeroen-van-der-veldenJeroen van der Velden 04/07/2016 at 09:570 Comments

Here is they layout and code to connect up to 9 pieces of Truck Hardware (2-wire) to an Arduino Pro Micro Board:

To download the Fritzing click HERE

Arduino IDE Code:

void setup() 
  {
  pinMode (2, INPUT_PULLUP);
  pinMode (3, INPUT_PULLUP);
  pinMode (4, INPUT_PULLUP);
  pinMode (5, INPUT_PULLUP);
  pinMode (6, INPUT_PULLUP);
  pinMode (7, INPUT_PULLUP);
  pinMode (8, INPUT_PULLUP);
  pinMode (9, INPUT_PULLUP);
  pinMode (10, INPUT_PULLUP);
  Keyboard.begin(); 
  } // end of setup
  
void loop() 
  {
  //if the button ispressed
  if(digitalRead(2)==LOW)
    {
    //charrcter to be send
    Serial.print("a");
    Keyboard.print("a"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(3)==LOW)
    {
    //charrcter to be send
    Serial.print("b");
    Keyboard.print("b"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(4)==LOW)
    {
    //charrcter to be send
    Serial.print("c");
    Keyboard.print("c"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(5)==LOW)
    {
    //charrcter to be send
    Serial.print("d");
    Keyboard.print("d"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(6)==LOW)
    {
    //charrcter to be send
    Serial.print("e");
    Keyboard.print("e"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(7)==LOW)
    {
    //charrcter to be send
    Serial.print("f");
    Keyboard.print("f"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(8)==LOW)
    {
    //charrcter to be send
    Serial.print("g");
    Keyboard.print("g"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(9)==LOW)
    {
    //charrcter to be send
    Serial.print("h");
    Keyboard.print("h"); 
    } // end of state change

    //if the button ispressed
  if(digitalRead(10)==LOW)
    {
    //charrcter to be send
    Serial.print("i");
    Keyboard.print("i"); 
    } // end of state change
    
  } // end of loop

So input 2+GND will send an "a". Input 3+GND will send a "b" and so on. Feel free to change the "#" to anything else!

Discussions