#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
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 colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String inputString = "";
const int ldr=A0;
const float GAMMA=0.7, RL10=50;
int parameterValue = 0;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(A0, INPUT);
const float GAMMA = 0.7;
const float RL10 = 50;
int analogValue = analogRead(ldr);
float voltage = analogValue/1024*5;
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
Serial.println(key);
inputString += key;
if (inputString.length() > 2) {
inputString = "";
lcd.clear();
}
if (key == 'A') {
// แปลงค่าที่ได้จาก key pad เป็นตัวเลขและกำหนดค่าให้กับ parameterValue
parameterValue = inputString.toInt();
// แสดงค่าที่ได้ใน Serial Monitor
Serial.println("Setting parameterValue to: " + String(parameterValue));
// รีเซ็ตตัวแปร inputString สำหรับการรับค่าใหม่
inputString = "";
lcd.print("LDR setting :" + String(parameterValue));
lcd.print(" Lux");
delay(500);
}
else if (key == 'B'){
lcd.clear();
}
// if (key = 'A' ){
// lcd.setCursor(0,0);
// // lcd.print("LDR setting :");
// // lcd.print("F A");
// lcd.print("LDR setting :");
// lcd.print(inputString);
// lcd.print(" Lux");
// }
// else if (key = 'A'){
// }
// lcd.setCursor(0,0);
delay(50);
}
}