I have a small program and I need it to record the keypress after the void inputScreen(). I made it so it writes the key into string, but how can I make it record all the keys in order, and when there are 6 key-presses to stop reading input and printing on LCD.
#include <glcd.h>
#include <Keypad.h>
#include <fonts/allfonts.h>
#include <EEPROM.h>
int led = 13;
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'},
{'C','0','E'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(led, OUTPUT);
GLCD.Init();
GLCD.SelectFont(Arial14);
welcomeScreen(); //Go to welcome screen and wait for 'C' key only. (I need to disable any other keys until void inputScreen)
}
void inputScreen()
{
GLCD.ClearScreen();
GLCD.CursorTo(3, 1);
GLCD.print("Va rugam");
GLCD.CursorTo(2, 2);
GLCD.print("Introduceti PIN");
GLCD.CursorTo(3, 3); //Here is where the six # characters will be entered.
digitalWrite(led, HIGH);
}
void welcomeScreen() //Draw a simple welcome screen.
{
GLCD.ClearScreen();
GLCD.CursorTo(0, 0);
GLCD.print("*********************");
GLCD.CursorTo(2, 1);
GLCD.print("Bine ati venit!");
GLCD.CursorTo(0, 3);
GLCD.print("*********************");
GLCD.CursorTo(3, 3);
digitalWrite(led, LOW); //Will attach it to a step motor later.
}
void loop(){
String pula; //This is where the pin entered has to be stored. (or any other type of memory input)
char key = keypad.getKey();
if (key != NO_KEY)
{
pula += (key);
GLCD.print("#"); //How do I make it print this ONLY on void inputScreen?
if (key == 'C')
{
delay(10);
inputScreen(); //Only on this keypress go to void inputScreen.
}
if (key == 'E') //This should work only AFTER the pin was entered. ... ?
{
delay(50);
GLCD.ClearScreen();
GLCD.CursorTo(3, 1);
GLCD.print("Va rugam");
GLCD.CursorTo(2, 2);
GLCD.print("ASTEPTATI");
GLCD.CursorTo(2, 3);
GLCD.print("#");
delay(500);
GLCD.CursorTo(3, 3);
GLCD.print("#");
delay(500);
GLCD.CursorTo(4, 3);
GLCD.print("#");
delay(500);
GLCD.CursorTo(5, 3);
GLCD.print("#");
delay(500);
GLCD.CursorTo(6, 3);
GLCD.print("#");
delay(500);
GLCD.CursorTo(7, 3);
GLCD.print("#");
delay(500);
GLCD.CursorTo(8, 3);
GLCD.print("#");
delay(500);
GLCD.ClearScreen();
GLCD.CursorTo(5, 1);
GLCD.print("PIN");
GLCD.CursorTo(4, 2);
GLCD.print(pula); //Here I want it to print out the pin that was entered (limited to 6) on the void inputScreen.
delay(2500);
welcomeScreen(); //Go back and wait for 'C' key to be pressed to go all over again.
}
}
}