#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#include <Keypad.h>
// Define the rows and columns of the keypad
const byte ROWS = 4;
const byte COLS = 4;
char key, key2;
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}; // Connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// Placeholder for sensor values
int sensor1Value = 0;
int T1_act = 0;
int T1_std = 0;
int Dt1_adj = 0;
uint32_t timer = millis();
char currentMenu = '0';
boolean inCalibration = false;
int newValue =0;
int i;
enum states {
M_A,
M_1,
M_2,
M_Cal,
M_3
};
states state;
void setup() {
Serial.begin(115200);
// Set up the LCD's number of columns and rows
lcd.init();
lcd.backlight();
lcd.begin(20, 4);
// Print the initial men
lcd.print(" AQMS MS2401");
lcd.setCursor(0, 1);
lcd.print(" Temp - Humy Logger");
lcd.setCursor(0, 2);
lcd.print (" MS Instruments");
lcd.setCursor(0, 3);
lcd.print (" Prog V0 20240530");
lcd.clear();
delay (1000);
//Setup Awal Ketika Running
state = M_A;
printInitialMenu();
}
void loop() {
if (millis() - timer > 1000) // tampil data setiap 1 detik
{
timer +=1000;
Serial.println("Cal Status = " + String(inCalibration));
Serial.println("Menu = " + String(currentMenu));
Serial.println("key Pressed = " + String(key));
}
key = keypad.getKey();
// Serial.println("Menu Awal");
// switch (state) {
// case M_A:
// if(key == 'A')
// state = M_1;
// else if(key == 'B')
// state = M_2;
// else if(key == 'C')
// state = M_3;
// else if(key == 'D')
// state = M_A;
// break;
// case M_1:
// Menu_1();
// break;
// case M_2:
// calibrationMenu();
// break;
// case M_3:
// Menu_3();
// break;
// default:
// break;
// }
if (key) {
switch (key) {
case 'A':
currentMenu = 'A';
Menu_1();
break;
case 'B':
currentMenu = 'B';
Menu_2();
break;
case 'C':
currentMenu = 'C';
Menu_3();
break;
case 'D':
currentMenu = 'D';
Serial.println("Menu D");
break;
default:
break;
}
}
// Simulate sensor readings
sensor1Value = 23; // Replace A8 with the actual pin for Sensor 1
T1_act = sensor1Value; //Replace A10 with the actual pin for Sensor 3
// Update the displayed sensor value
updateSensorValue();
}
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();
}
void calibrationMenu() {
key2 = key;
newValue = key2 - '0';
if (key2)
{
i=0;
Serial.println("Password = " + String(newValue));
// lcd.setCursor(8+i, 1);
// lcd.print(newValue);
newValue++;
}
// switch (key) {
// case '0'...'9': // If a numeric key is pressed
// i=0;
// newValue = newValue * 10 + (key - '0');
// lcd.setCursor(8+i, 1);
// lcd.print(newValue);
// newValue++;
// break;
// case '#': // If the '#' key is pressed, end input and store the value
// T1_std = newValue;
// calculateDt1Adj();
// newValue = 0;
// break;
// case 'D': // If the 'D' key is pressed, end calibration
// Serial.println("HALOOOOOOO");
// currentMenu = '0'; // Return to Menu
// break;
// }
}
void calculateDt1Adj() {
Dt1_adj = T1_act - T1_std;
}
void updateSensorValue() {
// lcd.setCursor(0, 1); // Move to the second line
// switch (currentMenu) {
// case 'A':
// lcd.print("Value: ");
// lcd.print(sensor1Value);
// break;
// // case 'B':
// // lcd.print("Value: ");
// // lcd.print(sensor2Value);
// // break;
// // case 'C':
// // lcd.print("Value: ");
// // lcd.print(sensor3Value);
// // break;
// default:
// break;
// }
}