#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte rowPins[ROWS] = {11, 10, 9, 8};
byte colPins[COLS] = {7, 6, 5, 4};
byte pinRelay = 2;
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.backlight();
pinMode(pinRelay, OUTPUT);
}
int count = 0;
void loop() {
char customKey = customKeypad.getKey();
if (customKey) {
if (customKey != 'C') {
lcd.print(customKey);
count++;
}
switch (customKey) {
case '*':
digitalWrite(pinRelay, HIGH);
break;
case '#':
digitalWrite(pinRelay, LOW);
break;
case 'C':
if (count > 0) {
count--;
}
lcd.setCursor(count, 0);
lcd.print(' ');
break;
}
if (count >= 16) {
count = 0;
lcd.clear();
lcd.setCursor(0, 0);
}
}
}