Hi guys,
I'm using Arduino sensor shield v5 for UNO board here and Graphic LCD 12864
Before I ask here, I had browsing about my problem, but still not working on my glcd ![]()
I want to input 2 characters from my keypad 4x4 to graphic lcd
From my code below, when I pressed 2 or more character from keypad, on my glcd just show first character i'd input, second character doesn't show on it, when i pressed '#', "tes" appear on my glcd.
But in serial monitor, every character I'd pressed were appear
So my question is, how to display second character on my glcd?
Here is my code
#include <Keypad.h>
#include "U8glib.h"
U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, A4, A3, A2); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
const byte ROWS = 4;
const byte COLS = 4;
char keymap[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keymap), rowPins, colPins, ROWS, COLS );
volatile int firstnumber = 99;
volatile int secondnumber = 99;
char key; // key should be a global variable, written in "loop()" and read in "draw()"
char key2;
char num1 = 99; //variable for compare that num1 & num2 were store
char num2 = 99;
void u8g_prepare(void) {
u8g.setFont(u8g_font_6x10);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
}
void draw2() {
u8g_prepare();
num1 = key;
delay(200);
if (num1 == '#') { //'#' for exit
num1 = ' '; // to clear num1
Serial.println("tes");
u8g.drawStr(0, 10, "tes ");
//u8g.setPrintPos(35, 0);
//u8g.print("tes");
} else {
if (num1 == 99) { //compare, num1 was inputted or not
num1 = key;
Serial.println(key);
char buf [2];
sprintf(buf, "%c", key);
u8g.drawStr(0, 10, buf);
}
}
}
void setup() {
Serial.begin(9600);
keypad.setHoldTime(250);
keypad.setDebounceTime(100);
}
void in() { //void for input from keypad
key = keypad.getKey();
if (key != NO_KEY) {
u8g.firstPage();
do {
draw2();
}
while ( u8g.nextPage() );
}
}
void loop() {
in();
}