11 years, 3 months ago.

Where is my error?

Hi! I need to read a membrane matrix keypad with my KL25Z this is my software where is the error?

prove2

#include "mbed.h"
#include "TextLCD.h"
  
BusIn colonne(PTC8,PTA5,PTA4);
BusOut righe(PTA12,PTD4,PTA2,PTA1);
TextLCD lcd(PTE5,PTE4,PTE3,PTE2,PTB11,PTB10);

char Keypad(void)
{
    char key = 10;
    righe.write(15);
    righe.write(14);
    switch(colonne)
    {
        case 3: key = 1; break;
        case 5: key = 2; break;
        case 6: key = 3; break;
    }
    righe.write(13);
    switch(colonne)
    {
        case 3: key = 4; break;
        case 5: key = 5; break;
        case 6: key = 6; break;
    }
    righe.write(11);
    switch(colonne)
    {
        case 3: key = 7; break;
        case 5: key = 8; break;
        case 6: key = 9; break;
    }
    righe.write(7);
    switch(colonne)
    {
        case 3: key = '*';
        case 5: key = 0;
        case 6: key = '#';
    }
    return key;
}

int main(void) 
{
    char key; 
    lcd.cls();
    while(1)
    {
        lcd.cls();
        key = Keypad();
        if(key != 10)
            lcd.printf("%c\n\r",&key); 
        wait(0.2);        
    }
}

I've mounted 8.2Kohm pull up resistors on columns pins.

P.S.: colonne = columns, righe = rows

2 Answers

11 years, 3 months ago.

You want to printf the returned key, which is a character.

 lcd.printf("%c\n\r",&key); 

What you actually print is the address of the 'key' variable.

Try

 lcd.printf("%c\n\r", key); 

You may also want to change the code in the keypad matrix scan function. In all cases except '*' and '#' you dont return printable characters but low ASCII codes (0, 1, 2 etc). These non-printable chars wont show on the LCD or serial terminal.

11 years, 3 months ago.

I've followed your suggestion now work but not show correct numbers

We really need more info than that? Didn't you just make a wiring error?

posted by Erik - 15 May 2013

Now work correctly

posted by Davide Luongo 16 May 2013