Hello, I have previously made a post about a project I'm creating for school using arduinos and have run into another issue that I cannot solve. My final project will be a jukebox, but for now, I want to make an enter key using a keypad, LCD, and Mega. The idea is that after entering a certain set of numbers (such as 123) and using the enter function to play a certain song, but for now, I just want the LCD to clear and display the letter 'a'. I cannot figure out how to make an enter key for a singular input and have tried using multiple variations of case statements and if statements.
Below is a diagram of my setup, an image of my setup, and my current code. Any help would be appreciated. Thank you!
//this is test code trying to make an enter button ONLY
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t rowPins[ROWS] = { 23, 25, 27, 29 }; // Pins connected to R1, R2, R3, R4
uint8_t colPins[COLS] = { 31, 33, 35, 37 }; // Pins connected to C1, C2, C3, C4
int cursor = 0;
int numbers[] = {};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.blink();
lcd.setCursor(0,0);
}
void loop()
{
char key = keypad.getKey();
/*if (key != NO_KEY && cursor < 16)
{
lcd.print(key);
switch (key)
{
default:
break;
case '*':
lcd.setCursor(0, 1);
lcd.clear(); // Clear the display
break;
}*/
/*switch (key == '1' && key == '2' && key != '3' && key != '4' && key != '5' && key != '6' && key != '7' && key != '8' && key != '9' && key != '0' && key != 'A' && key != 'B' && key != 'C' && key != 'D')
{
case '#':
lcd.setCursor(0, 1);
lcd.clear(); // Clear the display
lcd.print("a");
break;
}
switch (key)
{
//if (key == '1' && key == '2' && key != '3' && key != '4' && key != '5' && key != '6' && key != '7' && key != '8' && key != '9' && key != '0' && key != 'A' && key != 'B' && key != 'C' && key != 'D')
//{
case '#':
lcd.setCursor(0, 1);
lcd.clear(); // Clear the display
lcd.print("a");
break;
//}
default:
//if (key != NO_KEY && cursor < 16)
break;
}*/
//}
if (key != NO_KEY && cursor < 16)
{
lcd.print(key);
if (key == '*')
{
lcd.setCursor(0, 1);
lcd.clear(); // Clear the display
}
}
if (key == '#')
{
if (key == '1')
{
lcd.print(key);
lcd.setCursor(0, 1);
lcd.clear(); // Clear the display
lcd.print("a");
}
}
}