I am using a 4x4 Universal Keypad and a SainSmart 12864 LCD screen in hopes to display numbers punched in from a keypad and then check against a stored string (In this case "I < 3 U"). I tried looking at other posts on this forum but haven't seen where anyone has printed using the keypad.getkey function. When I run this code, I DO get the correct inputs on the serial monitor when I punch the keys (though they are laggy). There is some problem using the ug8.print function(key) when key is set by keypad.getkey (it works when I set to a integer like "399").
#include <Keypad.h>
#include "U8glib.h"
U8GLIB_ST7920_128X64 u8g(13, 11, 12, U8G_PIN_NONE);
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','<'},
{'4','5','6','>'},
{'7','8','9','='},
{'*','0','I','U'}
};
byte rowPins[ROWS] = {2,3,4,5}; //connect to row pinouts
byte colPins[COLS] = {6,7,8,9}; //connect to column pinouts
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char key; //= keypad.getKey(); [color=green]//I feel like I should make this a global variable, but it doesn't seem to make much difference either way.[/color]
void draw(void) {
char key = keypad.getKey();
u8g.setFont(u8g_font_osb18);
u8g.setPrintPos(0, 18);
u8g.print(key);
}
void setup(){
Serial.begin(9600);
}
void loop(){
u8g.firstPage();
char key = keypad.getKey();
do {
draw();
} while( u8g.nextPage() );
delay(500);
if (key != NO_KEY){
Serial.println(key);
}
}