Menu

4x17 Matrix

2017-04-21
2017-04-21
  • Chrigu Wuethrich

    Hi i have a Board with 4x16 Matrix and an Arduino Mega 2560. Now i have changed the config to 4x17 that i also can use the Buttons.
    Btn1 pin 2 to 39
    Btn2 pin 3 to 39
    Btn3 pin 4 to 39
    If you want you can add the configuration to the source
    cheers
    chrigu

    /*#include <Keypad.h>
    */
    const byte numRows = 4; //four rows
    const byte numCols = 17; //four columns
    const int debounceTime = 100;//20 works better than great !
    //define the cymbols on the buttons of the keypads
    char keymap[numRows][numCols] = {
    {'0','1','2','3','4','5','6','7','8','9','*','B','C','D','E','F','G'},
    {'a','b','c','d','e','f','g','h','i','?','K','L','M','N','O','P','Q'},
    {'j','k','l','m','n','o','p','q','r','&','T','U','V','W','X','Y','Z'},
    {'s','t','u','v','w','x','y','z','A','@','+','-',']','/','!','$','H'}
    };
    byte rowPins[numRows] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
    byte colPins[numCols] = {22, 23, 24, 25, 26, 27 ,28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39}; //connect to the column pinouts of the keypad
    
    //initialize an instance of class NewKeypad
    /*Keypad customKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
    */
    void setup()
    {
    Serial.begin(9600);
    for (int row = 0; row < numRows; row++)
    {
    pinMode(rowPins[row],INPUT); // Set row pins as input
    digitalWrite(rowPins[row],HIGH); // turn on Pull-ups
    }
    for (int column = 0; column < numCols; column++)
    {
    pinMode(colPins[column],OUTPUT); // Set column pins as outputs
    // for writing
    digitalWrite(colPins[column],HIGH); // Make all columns inactive
    }
    }
    
    void loop()
    {
    char key = getKey();
    if( key != 0) { // if the character is not 0 then
    // it's a valid key press
    /*Serial.print("Got key ");*/
    Serial.print(key);
    }
    }
    
    // returns with the key pressed, or 0 if no key is pressed
    char getKey()
    {
    char key = 0; // 0 indicates no key pressed
    
    for(int column = 0; column < numCols; column++)
    {
    digitalWrite(colPins[column],LOW); // Activate the current column.
    for(int row = 0; row < numRows; row++) // Scan all rows for
    // a key press.
    {
    if(digitalRead(rowPins[row]) == LOW) // Is a key pressed?
    {
    delay(debounceTime); // debounce
    while(digitalRead(rowPins[row]) == LOW)
    ; // wait for key to be released
    key = keymap[row][column]; // Remember which key
    // was pressed.
    }
    }
    digitalWrite(colPins[column],HIGH); // De-activate the current column.
    }
    return key; // returns the key pressed or 0 if none
    }
    
     

    Last edit: Chrigu Wuethrich 2017-04-21
    • diego

      diego - 2017-04-21

      hi,
      you have 2 characters 'A' in your ligne/column matrix...

       
      • Chrigu Wuethrich

        thx diego
        i have changed one to H

         
  • poilou

    poilou - 2017-04-21

    HI Chrigu,
    Please include your code in the "code" tags, I suspect that the file is not properly displayed in the message above.

     

Anonymous
Anonymous

Add attachments
Cancel