#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
// Inisialisasi keypad
const byte ROWS = 4; //jumlah baris pada keypad
const byte COLS = 4; //jumlah kolom pada keypad
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13, 12, 14, 27}; //sesuaikan pinnya sesuai dengan koneksi Anda
byte colPins[COLS] = {26, 25, 33, 32}; //sesuaikan pinnya sesuai dengan koneksi Anda
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Inisialisasi LCD
LiquidCrystal_I2C lcd(0x27, 20, 4); // Alamat I2C default untuk LCD 20x4 adalah 0x27
char key;
int sensor1Value = 0;
int T1_act = 24;
int T1_std = 0;
int Dt1_adj = 0;
uint32_t timer = millis();
char currentMenu = '0';
boolean inCalibration = false;
String newValue ="";
int i;
int a;
int isi= 0;
boolean awal = false;
boolean menu = false;
boolean menu1 = false;
boolean menu2 = false;
boolean menu3 = false;
boolean t1Calmode = false;
boolean t1Caled = false;
void setup() {
// Inisialisasi LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Keypad dan LCD I2C");
lcd.setCursor(0, 1);
lcd.print("Silakan tekan tombol");
Serial.begin(115200);
a=0;
}
void loop() {
// if (key) {
// lcd.clear();
// lcd.setCursor(0, 0);
// lcd.print("Tombol ditekan:");
// lcd.setCursor(0, 1);
// lcd.print(key);
// }
if(a==0)
{
printInitialMenu();
a=1;
}
key = keypad.getKey();
if(key == 'A')
{
Menu_1();
menu1 = true;
}
else if(key == 'B'){
// Menu_2();
menu2 = true;
// lcd.clear();
// lcd.setCursor(0, 0);
// lcd.print("T1 act: ");
// lcd.print(T1_act);
// lcd.print(" *c");
// i=1;
// key = keypad.getKey();
// if (key != NO_KEY){
// if (key == '0' || key == '1' || key == '2' || key == '3' ||
// key == '4' || key == '5' || key == '6' || key == '7' ||
// key == '8' || key == '9' ) {
// newValue += key;
// lcd.clear();
// lcd.setCursor(i,1);
// lcd.print("*");
// Serial.println(newValue);
// i++;
// }
// }
// if (i > 5 || key == '#') {
// newValue = "";
// i=1;
// lcd.clear();
// lcd.setCursor(i,1);
// lcd.print("*");
// }
// if (key == '*') {
// i=1;
// // T1_std = newValue;
// t1Calmode = false;
// a = 0;
// }
}
else if(key == 'C'){
Menu_3();
menu3 = true;
}
if(menu2==true)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("T1 act: ");
lcd.print(T1_act);
lcd.print(" *c");
i=1;
key = keypad.getKey();
if (key != NO_KEY && isi ==0){
if (key == '0' || key == '1' || key == '2' || key == '3' ||
key == '4' || key == '5' || key == '6' || key == '7' ||
key == '8' || key == '9') {
isi =0;
newValue += key;
lcd.clear();
lcd.setCursor(i,1);
lcd.print("*");
Serial.println(newValue);
i++;
}
isi =1;
}
if (i > 5 || key == '#') {
newValue = "";
i=1;
lcd.clear();
lcd.setCursor(i,1);
lcd.print("*");
}
if (key == '*') {
i=1;
// T1_std = newValue;
t1Calmode = false;
a = 0;
}
}
}
void printInitialMenu() {
lcd.clear();
lcd.print("YYYY,MM,DD,hh,mm,ss");
lcd.setCursor(0, 1);
lcd.print("A. Menu 1");
lcd.setCursor(0, 2);
lcd.print (" B. Menu 2");
lcd.setCursor(0, 3);
lcd.print (" C. Menu 3");
}
void Menu_1()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Current Monitoring");
lcd.print(sensor1Value);
}
void Menu_3()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Recording....");
// lcd.print(sensor1Value);
}
void Menu_2() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("T1 act: ");
lcd.print(T1_act);
lcd.print(" *c");
lcd.setCursor(0, 1);
lcd.print("T1 std: ");
lcd.print(T1_std);
lcd.print(" *c");
// calculateDt1Adj();
lcd.setCursor(0, 2);
lcd.print("Dt1 adj: ");
lcd.print(Dt1_adj);
lcd.print(" *c");
// calibrationMenu();
}