arduino mini matrix keyboard

I am trying to make a 3 * 3 matrix keyboard with Arduino Mini . I find problems in achieving because I use 9 LEDs corresponds to a button on the keyboard so when I press a button one of the LEDs lights. thank you to share me your ideas ;)

Please share your code and wiring diagram.

dup of http://forum.arduino.cc/index.php?topic=410790.0

med_am: I find problems in achieving because I use 9 LEDs

What problems did you find? Use 6 pins for the keyboard (2,3,4,5,6,7) and 9 pins for the LEDs (8,9,10, 11,12,13, A0,A1,A2). That leaves you Serial (0,1) and three more pins (A3, A4, A5) for digital I/O or analog input and two more (A6, A7) for analog input.

that was my code

int ligne[3]={2,3,4}; //tableau pour stocker les pins des lignes
int colonne[3]={5,6,7}; //tableau pour stocker les pins des colonnes

const int LED1=8;
const int LED2=9;
const int LED3=10;
const int LED4=11;
const int LED5=12;
const int LED6=13;
const int LED7=A0;
const int LED8=A1;
const int LED9=A2;

void setup() {

pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
pinMode(LED8, OUTPUT);
pinMode(LED9, OUTPUT);

//mise en OUTPUT et LOW des lignes et INPUT des colonnes
for (int i=0;i<2;i++){
pinMode(ligne*, OUTPUT);*
digitalWrite(ligne*,LOW);*
pinMode(colonne*, INPUT);*
}
Serial.begin(9600); //communication série
}
void loop() {
test(); //appel de la fonction test
}
//fonction de test des états des boutons
void test(){

* digitalWrite(ligne[0], HIGH); //on place la ligne en HIGH*
* for ( int c=0;c<=2;c++) {*
* if( colonne[0]== HIGH)*
* {digitalWrite(LED1, HIGH);delay(100);}*
* else if( colonne[1]== HIGH)*
* {digitalWrite(LED2, HIGH);delay(100);}*
* else{digitalWrite(LED3, HIGH);delay(100);}*
* }*
* digitalWrite(ligne[1], HIGH); //on place la ligne en HIGH*
* for ( int c=0;c<=2;c++) {*
* if( colonne[0]== HIGH)*
* {digitalWrite(LED4, HIGH);delay(100);}*
* else if( colonne[1]== HIGH)*
* {digitalWrite(LED5, HIGH);delay(100);}*
* else{digitalWrite(LED6, HIGH);delay(100);}*
* }*
* digitalWrite(ligne[2], HIGH); //on place la ligne en HIGH*
* for ( int c=0;c<=2;c++) {*
* if( colonne[0]== HIGH)*
* {digitalWrite(LED7, HIGH);delay(100);}*
* else if( colonne[1]== HIGH)*
* {digitalWrite(LED8, HIGH);delay(100);}*
* else{digitalWrite(LED9, HIGH);delay(100);}*
* }*
delay(100); //petite attente

}

well in your test function you don't read the values for colonne[xx] after powering the ligne[] so that can't work... :)

and please reformat your post above to use the code tags.

i use this forum recently and i don't know how to use the code tags :/

med_am: i use this forum recently and i don't know how to use the code tags :/

Did you read this before posting a programming question ?

i made changes but i found another problems.
this is my code:

 int ligne[3]={2,3,4}; //tableau pour stocker les pins des lignes
int colonne[3]={5,6,7}; //tableau pour stocker les pins des colonnes

const int LED1=8;
const int LED2=9;
const int LED3=10;
const int LED4=11;
const int LED5=12;
const int LED6=13;
const int LED7=A0;
const int LED8=A1;
const int LED9=A2;


void setup() {

pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
pinMode(LED8, OUTPUT);
pinMode(LED9, OUTPUT);

//mise en OUTPUT et LOW des lignes et INPUT des colonnes
for (int i=0;i<2;i++){
pinMode(ligne[i], OUTPUT);
digitalWrite(ligne[i],LOW);
pinMode(colonne[i], INPUT);
}
Serial.begin(9600); //communication série
}

void loop() {
test(); //appel de la fonction test
}
//fonction de test des états des boutons

void test(){
  
  digitalWrite(ligne[0], HIGH); //on place la ligne en HIGH
   for ( int c=0;c<=2;c++) {
digitalRead(colonne[c]);
    if( colonne[0]== HIGH)
     {digitalWrite(LED1, HIGH);delay(100);}
    else if( colonne[1]== HIGH)
     {digitalWrite(LED2, HIGH);delay(100);}
    else{digitalWrite(LED3, HIGH);delay(100);}
   }
  digitalWrite(ligne[1], HIGH); //on place la ligne en HIGH
   for ( int c=0;c<=2;c++) {
digitalRead(colonne[c]);
    if( colonne[0]== HIGH)
     {digitalWrite(LED4, HIGH);delay(100);}
    else if( colonne[1]== HIGH)
     {digitalWrite(LED5, HIGH);delay(100);}
    else{digitalWrite(LED6, HIGH);delay(100);}
   }
    digitalWrite(ligne[2], HIGH); //on place la ligne en HIGH
   for ( int c=0;c<=2;c++) {
digitalRead(colonne[c]);
    if( colonne[0]== HIGH)
     {analogWrite(LED7, HIGH);delay(100);}
    else if( colonne[1]== HIGH)
     {analogWrite(LED8, HIGH);delay(100);}
    else{analogWrite(LED9, HIGH);delay(100);}
   }
delay(100); //petite attente
   
}

med_am:
i made changes but i found another problems.

What problems?

this is the result of my simulation just 2 LEDs works without pressing the button , and the others don’t works.

Capture.PNG

The changes you made are not the ones I suggested above…

this is your first test

  digitalWrite(ligne[0], HIGH); //on place la ligne en HIGH
  for ( int c = 0; c <= 2; c++) {
    digitalRead(colonne[c]);
    if ( colonne[0] == HIGH)
    {
      digitalWrite(LED1, HIGH);
      delay(100);
    }
    else if ( colonne[1] == HIGH)
    {
      digitalWrite(LED2, HIGH);
      delay(100);
    }
    else {
      digitalWrite(LED3, HIGH);
      delay(100);
    }
  }

so you send some electricity to power ligne[0], that’s good. then you want to see if some current is flowing into one of the colonne.

in the if you do a digitalRead(colonne[c]); what do you think this does and where does the value you read goes?

Also when you go power the next “ligne”

digitalWrite(ligne[1], HIGH); //on place la ligne en HIGH

what happens to the first ligne? do you think it’s still also getting power?.. think about it…
same applies for the if and then for ligne 3

thank you but i don't find a clear solution yet. i don't know what to do exactly

digitalRead(colonne[c]);Describe in words what this line does.

it means read the colonnevalue

I would handle it this way _ I hate giving away full solutions though (but need to go and it’s totally untested, juste typed it in)

declare your global variables

int ligne[3] = {2, 3, 4}; //tableau pour stocker les pins des lignes
int colonne[3] = {5, 6, 7}; //tableau pour stocker les pins des colonnes

const int LED1 = 8;
const int LED2 = 9;
const int LED3 = 10;
const int LED4 = 11;
const int LED5 = 12;
const int LED6 = 13;
const int LED7 = A0;
const int LED8 = A1;
const int LED9 = A2;

// vérifier que l'ordre des LED dans le tableau ci dessous correspond bien à l'ordre dans votre afficheur
const int mesLEDs[3][3] = {
  {LED1, LED2, LED3},
  {LED4, LED5, LED6},
  {LED7, LED8, LED9}
};

notice I created a new bi dimensional array with the LEDs; you need to ensure they are ordered in the right way for your columns / rows I did not check in details

then in the loop I would do something like this

  for ( int maLigne = 0; maLigne <= 2; maLigne++) { // pour chaque ligne de bouton
    digitalWrite(ligne[maLigne], HIGH); //on place cette ligne en HIGH
    for ( int maColonne = 0; maColonne <= 2; maColonne++) { // pour chaque colonne de boutons
      // on regarde s'il y a du courant en bas d'une des colonnes
      // si on a un HIGH dans colonne[maColonne] alors on allume la LED correspondante, sinon on l'éteint
      digitalWrite(mesLEDs[maLigne][maColonne], digitalRead(colonne[maColonne]));
    } // fin de l'analyse de cette colonne
    digitalWrite(ligne[maLigne], LOW); //on cesse d'alimenter la ligne
  } // fin de l'analyse de cette ligne

You iterate for each line and each column, check if the button is pressed or not and turn on or off the associated LED.

med_am: it means read the colonne

 value 
[/quote]Correct, but what do you do with once it has been read ?