Can't read value of char

Hi everyone,

I’m trying to read the value of a char here, but I can’t get it to work. The idea is that when key 1 is pressed on the keypad, you woud display a 1 on a 7seg display using the max7219. However, I can’t get the value of the char.

Here’s my code:

#include <Keypad.h>
#include <LedControl.h>
LedControl mydisplay = LedControl(6, 7, 8, 1);
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’#’,‘0’,’*’}
};
byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 10, 11}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
Serial.begin(9600);
mydisplay.shutdown(0, false); // turns on display
mydisplay.setIntensity(0, 1); // 15 = brightest

}

void loop(){
char k = keypad.getKey();
if (k != ‘1’){
mydisplay.setDigit(0, 0, 1, false);
}

}

This displays a 1 always.

If I changed it into this
if (k != 1)

nothing happens.

Any ideas?

Jens

if (k != '1'){
    mydisplay.setDigit(0, 0, 1, false);
    }

Shouldn't that be "if (k == '1')"? Why display 1 whenever k is NOT equal to '1'?

Thank you very much!

Does also someone know how to display a ten?

Because I can only go from 0 to 9. How can I say if button 1 and button 0 is pressed?

jensvde:
Does also someone know how to display a ten?
Because I can only go from 0 to 9. How can I say if button 1 and button 0 is pressed?

How do you want to signal that you have finished entering data? If you press '1' how is the sketch going to know if you are typing "1" or typing the start of "10"?

johnwasser:
How do you want to signal that you have finished entering data? If you press '1' how is the sketch going to know if you are typing "1" or typing the start of "10"?

Well I was also thinking about that. Maybe you can do it this way: type the number on the keypad (for example 10) and then press # to insert it.

Is that possible?