Making some headway with my little project but I've hit a wall that I can't seem to find a way around.
The circuit is just a matrix keypad and a I2C LCD shield hooked to my UNO.
Here's the sketch so far:
/*********************
Matrix KeyPad serial log and display via 16x2 character LCD.
This code was started using Adafruit's RGB LCD shield example code ("hello wold")
and suplimented with a keypad example sketch.
**********************/
//Including the required libraries:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
/* The shield uses the I2C SCL and SDA pins. On classic Arduinos
this is Analog 4 and 5 so you can't use those for analogRead() anymore
However, you can connect other I2C sensors to the I2C bus and share
the I2C bus.*/
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
/*Setup for the matrix keypad:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
//define the symbols on the buttons of the keypads:
char hexaKeys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad:
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void setup()
{
Serial.begin(9600); // Debugging output
lcd.begin(16, 2); // Set up the LCD's number of columns and rows:
lcd.print("Enter PassCode");
}
uint8_t i=0;
void loop()
{
char customKey = customKeypad.getKey();
{
lcd.setCursor(0, 1); //Set col/row on lcd (0=1st column, 1=2nd row)
lcd.print("Push # when done"); //Print "Push # when done" on bottom row LCD
}
if (customKey) //*Checking if a key is pressed/which key is pressed.
{
Serial.print(customKey); //*Print the key that was pressed to serial.
lcd.setCursor(1,0); //*Stating where to print on LCD (bottom row=0, first char = 1)
lcd.clear(); //*Not sure what this does. Things get weird if I remove it...
lcd.print("*"); //*Print " * " on the above specified char place.
}
}
The overview so far is
- Display "Enter PassCode" on top row of LCD and "Push # when done" on the bottom.
- Press a button on keypad.
- Send pressed key to serial monitor and display " * " on first row of LCD.
Now what I want it to do is add another " * " on the LCD for each entry.
What it is doing is just keeping the one " * ". (I know that's all it will do via the sketch above, but I've tried a few things and it either gives the same result, or does funky flickering gibberish.)
I'm guessing I need to establish that the keypad entries are part of a sequence. Ultimately, this will be necessary for passcodes and such, but I'm not there yet. One step at a time, hah.
So any clues on how I go about telling the UNO to wait for the next input (some sort of "then" statement?)? Assume I know nothing because in truth, I probably know less.
~Rev