Problem changing char position after input. (16x2 char LCD)

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. :slight_smile:

~Rev

What are those braces for?

{
    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
  }

remove them!

lcd.clear(); //*Not sure what this does. Things get weird if I remove it...

It clears the LCD display - the clue is in the name. This is why you only get one *. Remove it and fix the weird.
Forum rule :- When some one says something is weird it is actually behaving exactly normally for the code you have written.

if (customKey)

If what? This is not a logic variable. You can try remembering the value of the previous key and only printing when this changes.

Hint:- Use Serial.print to find out what variables take on what values in your code when running.

Okay, so I'm still having more of less the same problem, but a lot has changed in the sketch.

/*
    Project Title: Numeric keypad with password and Serial Monitor
    Link: www.newtechandme.com
    Uses e-gizmo's development board
    Uses analog pin as digital pin
    Uses keypad library for Arduino http://www.arduino.cc/playground/uploads/Code/Keypad.zip
    Uses Password library for Arduino http://www.arduino.cc/playground/uploads/Code/Password.zip
    4/5/2012 Updates Nathan Sobieck: Nathan@Sobisource.com
    3/11/2013 updated by newtechandme.com
 
*/
 
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h> 
#include <Password.h>
#include <Keypad.h>
#include <LiquidCrystal.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield(); 
 
Password password = Password( "123456" ); //This is our password

 
const byte ROWS = 4; // 4 rows
const byte COLS = 3; // 3 columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
 
byte rowPins[ROWS] = {8, 7, 6, 5};// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = {4, 3, 2};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
 
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
 
void setup()
{
  pinMode(13, OUTPUT);
  lcd.begin(16, 2);
  lcd.setCursor(3,0);
  lcd.print("custom splash");
  lcd.setCursor(3,1);
  lcd.print("yay!!");
  delay(2000);
  lcd.clear();
  lcd.setCursor(1,0);
  lcd.print("Enter PassCode");
  lcd.setCursor(0,1);
  lcd.print("Push # when done");
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
 
void loop()
{
  lcd.setCursor(0, 1);
  keypad.getKey();
}
 
//check the keypad events
void keypadEvent(KeypadEvent keyPress)
{
  switch (keypad.getState())
  {
    case PRESSED:
    lcd.print(keyPress); //print the keypress
    switch (keyPress)
    {
      case '#':
            checkPassword();
          break;
 
          case '*':
            password.reset();
            digitalWrite(15, LOW);
            lcd.setCursor(0,1);
            lcd.print("                ");
          break;
 
          default:
          password.append(keyPress);
     }
  }
}
 
//check the entered password
void checkPassword(){
  if (password.evaluate()) //if password is correct
  {
    lcd.clear();
    lcd.setCursor(1,1);
    lcd.print("Access Granted"); //print a message on serial monitor
    digitalWrite(13, HIGH); //turn ON an LED
    password.reset(); //reset password
  }
  else
  {
    lcd.clear();
    lcd.setCursor(1,1);
    lcd.print("Access Denied."); //if password is wrong
    digitalWrite(12, HIGH); //blink an LED
    delay(1000);
    digitalWrite(12, LOW);
    delay(1000);
    digitalWrite(12, HIGH);
    delay(1000);
    digitalWrite(12, LOW);
    delay(1000);
    digitalWrite(12, HIGH);
    delay(1000);
    digitalWrite(12, LOW);
    password.reset(); //reset password
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("Enter PassCode");
    lcd.setCursor(0,1);
    lcd.print("Push # when done");
  }
}

I think the part of this code that pertains to the display after key-press is:

    case PRESSED:
    lcd.print(keyPress); //print the keypress
    switch (keyPress)

I'm still figuring out what everything is doing in this sketch, but I think this is the chunk I want to change to get my " * " displaying. As it sits, it just displays the actual key that was pressed in the first column of the second row (without clearing the rest of the text)

So, if I press the "3" key on the pad, the LCD reads:

" Enter PassCode "
"3ush # when done"

Likewise, if I press "4" next, it just changes to:

" Enter Passcode "
"4ush # when done"

Am I on the right track?

I think the problem is with the way you are using the Password library, I do not know what it does and you didn't post a link to it. However it would seem that it is doing the printing to the LCD. So have a look at the documentation about how to use it.

Grumpy_Mike:
I think the problem is with the way you are using the Password library, I do not know what it does and you didn't post a link to it. However it would seem that it is doing the printing to the LCD. So have a look at the documentation about how to use it.

Cool, I'm on it! :slight_smile:

Thanks.