HELP !! Add 2 buttons to pin 6 & 7 too an already written multiplexing script ?

Hello all, :slight_smile:

I’m totaly new to this and i have build a wheel rim for my racing simulator rigg.

I have borrowed an 3x4 script from an button box tutorial, and I’am useing 11 button of the 3x4 matrix.

Problem is that I want to add my 2 paddle-shifter buttons and do this by adding the the buttons that are hocked upp to GND and pin 6 & 7 on my micro arduino card.

Could any one please help me ?? :slight_smile: :slight_smile: :slight_smile:

Is it even possible to bake it into the already written code ?

I dont want to open the wheel and rewire things again and was hopping this way may work !

I would be sooo gratefull if some one could help me, a newbi in this project :slight_smile:

Best regards Andreas, sorry for my poor english.

Here is my script i use for the other buttons on the wheelplate :

#include <Joystick.h>

// ----------------------------------------------------- Joystick Buttons -------------------------------------------
// ----------------------------------------------------- 
// Array of pins for the columns
int cPins[] = {3, 4, 5};

// Number of pins in the column array
int cPinsNo = 3;

// Array of pins for the rows
int rPins[] = {A1, A2, A3, A0};

// Number of pins in the row array
int rPinsNo = 4;

// Array for the last known switch states [cPinsNo][rPinsNo]
int colPrev[3][4] = {0};

// Key codes to be used for each button
// (see table above for codes to use)
// (columns and rows are transposed on device)
// [cPinsNo][rPinsNo]

uint8_t buttonCodes[3][4] = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11}
};

void setup()
{


Serial.begin(9600);  // output  

// Initialize Joystick Library
Joystick.begin();

for(int cPin = 0; cPin < cPinsNo; cPin++){
 pinMode(cPins[cPin], OUTPUT);
 digitalWrite(cPins[cPin], HIGH);
}

for(int rPin = 0; rPin < rPinsNo; rPin++){
 pinMode(rPins[rPin], INPUT);
 digitalWrite(rPins[rPin], HIGH);
}




}

void loop() {
// Loop through the columns
for(int cPin = 0; cPin < cPinsNo; cPin++){
 digitalWrite(cPins[cPin], LOW);

 // Loop through the rows
 for(int rPin = 0; rPin < rPinsNo; rPin++){
   // Check if each switch is pressed
   if(digitalRead(rPins[rPin]) == LOW){
     // Check to see if the state has changed since last time
     if(colPrev[cPin][rPin] == 0){
       Joystick.pressButton(buttonCodes[cPin][rPin]);
       // Update last known state of this switch
       colPrev[cPin][rPin] = 1;
     }
   } else {
     // Check to see if the state has changed since last time
     if(colPrev[cPin][rPin] == 1){
       Joystick.releaseButton(buttonCodes[cPin][rPin]); 
       // Update last known state of this switch
       colPrev[cPin][rPin] = 0;
     }
   }
 }
 digitalWrite(cPins[cPin], HIGH);
}

}

u have a 3x4 array but u havent told us if u use all 12.. that makes a difference..

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

…R

Hello again,

Big thanks for your replys !

I have edited the original code and wrote that I use 11 buttons of the 3x4 matrix and also made the script in “code” mode.

I already have a code that works for the paddels witch I used befor I wiried the 3x4 layout.

So maby it’s possible to use the PIN 6 & 7 script and inplant it into this code ?

#include <Joystick.h>

void setup(){
  //Start Serial
  Serial.begin(9600);
  Serial.println("Buttons Test");

  //Set the Column Pin Mode
  Serial.println("Setting Column Pins...");


  // Initialize Joystick Library
  Joystick.begin(); 
  
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);

  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH);
  
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);

  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);

}

void loop(){
  
  if(digitalRead(4) == LOW){
    Joystick.pressButton(4);
  }else{
    Joystick.releaseButton(4);
  }
  
  if(digitalRead(5) == LOW){
    Joystick.pressButton(5);
  }else{
    Joystick.releaseButton(5);
  }
  
  if(digitalRead(6) == LOW){
    Joystick.pressButton(6);
  }else{
    Joystick.releaseButton(6);
  }
  
  if(digitalRead(7) == LOW){
    Joystick.pressButton(7);
  }else{
    Joystick.releaseButton(7);
  }
  
  if(digitalRead(8) == LOW){
    Joystick.pressButton(8);
  }else{
    Joystick.releaseButton(8);
  }
  
  if(digitalRead(9) == LOW){
    Joystick.pressButton(9);
  }else{
    Joystick.releaseButton(9);
  }
}

/ Andreas

u have already use pins 6 and 7–

}else{
Joystick.releaseButton(6);
}

if(digitalRead(7) == LOW){
Joystick.pressButton(7);
}else{
Joystick.releaseButton(7);

if u have already used 11 of 12 in ur array, obviously u will need to make the array larger to
accomodate 2 more inputs…

u need to ur entire sketch…

blackwoodsjack..

I'am all new to this and sorry for my pale knowledge of this but please hear my tought..

I been wiring acoording to the 3x4 button box guide and using 11 of the 12 buttons.

That is the code I use now, the 3x4 code. by using the PIN 3 & 4 & 5 and on the otherside of the ardunio card the PIN A0,1,2,3,4.

Before that I got a spripted code for use of only up to 8 buttons by only using the GND PIN and the 1-9 PIN. ..nothing else, just use the 2 wire buttons ( one wire from eatch button to the GND and the other wire to eatch PIN 1 & 2 & 3 & 4 & 6 & 7 & 8 & 9 etc. ) and all was good.

So...

When I finaly made the wiring for the 3x4 matrix I forgott to include the Paddle-Shifter buttons..

And I just did not deer to "add" the new 2 buttons to the wired 3x4 matrix so I just putted them on GND and the free un-used PIN 6 & 7 on the board.

So the first script code is the one I'am using for the 11 button on the frontpannel of my Wheel rim,

..the second script code (the 8 button code, whit only GND + PIN 1-9) is the one I used Before I start using the 3x4 matrix code..

And I was hoping that maby it's possible to add a script path in the 3x4 codescript to add function to the free un-used PIN 6 & 7 on the card.. and maby it's possibly tho find that code by copy paste some script lines from the first and old GND 1-8 button code.

I'am soo sorry for this long and probebly miss understanding mess I now have written but,

Hopefully you geta clear Picture of my problem and by one way or the other can help me to solve the add of the 2 buttons that i have hocked up to the free pin 6 & 7 in the first 3x4 matrix scriptcode..

Oh god, you have by all daubt stop to read by now :) :) :)

But if not, thanks for your patient !

Best Regards, Andreas from sweden whit the terribly Spelling :)

joyStick() may only be 3x4..ok... no problem-- depending on ur arduino board.. do u have 2 unused pins..

if so-- declare them as inputs-- pinMode(unused_pinX,INPUT);

//pullup??

etc..

then just scan them after joyStick()..

digitalRead(unused_pinX)

and work with state of that pin......

I dont know anything about coding so I just don’t understand were to putt this info into the script. ? :o

PIN 6 & 7 is free on my ardunio board…

Could you please help me and Wright the codescript for the free PIN 6 & 7 in the codescript downbelow ?

#include <Joystick.h>

// ----------------------------------------------------- Joystick Buttons -------------------------------------------
// ----------------------------------------------------- 
// Array of pins for the columns
int cPins[] = {3, 4, 5};

// Number of pins in the column array
int cPinsNo = 3;

// Array of pins for the rows
int rPins[] = {A1, A2, A3, A0};

// Number of pins in the row array
int rPinsNo = 4;

// Array for the last known switch states [cPinsNo][rPinsNo]
int colPrev[3][4] = {0};

// Key codes to be used for each button
// (see table above for codes to use)
// (columns and rows are transposed on device)
// [cPinsNo][rPinsNo]

uint8_t buttonCodes[3][4] = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11}
};

void setup()
{


Serial.begin(9600);  // output  

// Initialize Joystick Library
Joystick.begin();

for(int cPin = 0; cPin < cPinsNo; cPin++){
 pinMode(cPins[cPin], OUTPUT);
 digitalWrite(cPins[cPin], HIGH);
}

for(int rPin = 0; rPin < rPinsNo; rPin++){
 pinMode(rPins[rPin], INPUT);
 digitalWrite(rPins[rPin], HIGH);
}




}

void loop() {
// Loop through the columns
for(int cPin = 0; cPin < cPinsNo; cPin++){
 digitalWrite(cPins[cPin], LOW);

 // Loop through the rows
 for(int rPin = 0; rPin < rPinsNo; rPin++){
   // Check if each switch is pressed
   if(digitalRead(rPins[rPin]) == LOW){
     // Check to see if the state has changed since last time
     if(colPrev[cPin][rPin] == 0){
       Joystick.pressButton(buttonCodes[cPin][rPin]);
       // Update last known state of this switch
       colPrev[cPin][rPin] = 1;
     }
   } else {
     // Check to see if the state has changed since last time
     if(colPrev[cPin][rPin] == 1){
       Joystick.releaseButton(buttonCodes[cPin][rPin]); 
       // Update last known state of this switch
       colPrev[cPin][rPin] = 0;
     }
   }
 }
 digitalWrite(cPins[cPin], HIGH);
}

}