Go Down

Topic: keypad question? (Read 534 times) previous topic - next topic

Nart

Feb 28, 2009, 11:31 am Last Edit: Feb 28, 2009, 11:51 pm by nart_schinakow Reason: 1
hello all,
i would like to interface a 3x4 keypad with my arduino without using the 74c922 encoder, so what is the code that i could use for this project ?
what will i connect rows as input colums ??????
any one know something ?

freezing

#1
Mar 02, 2009, 04:58 am Last Edit: Mar 02, 2009, 05:00 am by sosox Reason: 1
u may use 7 pins to scan the key . 4 pins for output and 3pins for input .the input conet to GND wiht a resistance to Pull Low  level .then as the key pressed one of the input should be draw high and u can read it. at one time just keep one ouput HIGH and the other pins ouput LOW ,and loop the 4 pins. when the key been pressed u can get the the specific weave of input and output pins.

retrolefty

And don't forget to use some form of software button filtering to eliminate contact bouncing as some matrix keyboards can be pretty flaky.

Lefty

Nart

thank you all for your replies, please can anyone just put the schematic of the keypad and the resistors ?

freezing

just a 4*4 keypad code .
Quote

void setup()  {
                Serial.begin(9600);
                for(i=0;i<4;i++)     pinMode((KeyOPin + i), OUTPUT);    
                for (i=0;i<4;i++)    pinMode(( KeyIPin + i), INPUT);  
          }    
void loop()
         {
            reg = 1;
            for (i=0;i<4;i++)
           {
                 for (n=0;n<4;n++)
                      {
                        if((reg>>n)&1)        digitalWrite(KeyOPin+n , HIGH);
                        else                        digitalWrite(KeyOPin+n , LOW);
                      }  
                 for (n=0;n<4;n++)
                      {
                         if(digitalRead(KeyIPin + n))
                              {    
                               key = key | (1<<(4+n));  
                               key = key|reg ;
                              }                    
                       }
                 reg = reg << 1;
              }

             if (key & 0xf0)
            {
                  if (key!=oldkey)   {   press = 1;  oldkey = key ; }
            }
            else       oldkey = 0;
 
             if (press)
           {
                Serial.print(key,BYTE);
           }
            press = 0;
            key = 0;
         }



Go Up