#include <Keypad.h> // เรียกใช้ library kaypad
#include <Wire.h> // เรียกใช้ไลบรารี่ I2C
#include <LiquidCrystal_I2C.h> //เรียกใช้ไลบรารี่จอ LCD_I2C
#include "RTClib.h"
LiquidCrystal_I2C lcd(0x27, 20, 4);
RTC_DS1307 rtc;
/* Keypad setup */
const byte KEYPAD_ROWS = 4; // กำหนด แถวของ keypad ที่ใช้
const byte KEYPAD_COLS = 4; // กำหนด คอลัม keypad ที่ใช้
byte rowPins[KEYPAD_ROWS] = {2, 3, 4, 5}; // กำหนดพอตที่ต่อ keypad
byte colPins[KEYPAD_COLS] = {A0, A1, A2, A3}; //กำหนดพอตทีต่อ keypad
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
void setup(){
pinMode(6, OUTPUT);
LiquidCrystal_I2C lcd(0x27,20,4); //เซตหมายเลขจอ 0x27และขนาดจอ LCD 20*4
//lcd.backlight(); // เปิดไฟback ligth ของจอ LCD
lcd.init();
if (! rtc.begin()) {
Serial.println("-----");
Serial.flush();
abort();
}
}
void loop(){
DateTime now = rtc.now();
lcd.backlight();
lcd.setCursor (6, 0);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.setCursor (0, 0);
lcd.print("");
LiquidCrystal_I2C lcd(0x27,20,4); //lcd.init();
char key = keypad.getKey();
if(key=='1'){digitalWrite(6,HIGH); lcd.setCursor(6,2);lcd.print("LED : ON "); }
if(key=='2'){digitalWrite(6,LOW); lcd.setCursor(6,2);lcd.print("LED : OFF");}
}