Enter function using keypad

Thank you! I will study up on terminators and see if I can use them to make this work :--)

IT WORKS! Thank you so much! I ended up putting this function in the loop :--D

Here's the new code:

//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);

    if (key == '*')
    {
      lcd.setCursor(0, 1);
      lcd.clear(); // Clear the display
    }
  }

    static char buffer[100] = {0};
  static int i = 0;

  if (key == '#')
  {
    buffer[i] = 123;
    i = 0;
    // Process buffer here...
    Serial.println(buffer);
    lcd.setCursor(0, 1);
    lcd.clear();
    lcd.print("a");
  }

  else
  {
    buffer[i] = key;
    i++;
    if (i == 100)
    {
      // Wrap around or do something more intelligent
      i = 0;
    }
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.