#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;
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {2, 3, 4, 5};
byte colPins[KEYPAD_COLS] = {A0, A1, A2, A3};
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);
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");
}
}