Difference between revisions of "Arduino: LCD DS1307 I2C RTC"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) (Created page with "center|400px|thumb Meterial yang diperlukan dalam tutorial kali ini adalah: 1. Arduino 2. LCD 16×2 3. I2C LCD 4. RTC DS1307 5. Library unt...") |
Onnowpurbo (talk | contribs) |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
Meterial yang diperlukan dalam tutorial kali ini adalah: | Meterial yang diperlukan dalam tutorial kali ini adalah: | ||
| − | + | * Arduino | |
| − | + | * LCD 16×2 | |
| − | + | * I2C LCD | |
| − | + | * RTC DS1307 | |
| − | + | * Library untuk I2C download disini atau disini. | |
| − | + | * Library untuk RTC DS1307 download disini. | |
| + | ==Library== | ||
| + | https://github.com/Erriez/ErriezDS1307/archive/refs/heads/master.zip | ||
| + | https://downloads.arduino.cc/libraries/github.com/adafruit/RTClib-2.1.1.zip | ||
| + | https://downloads.arduino.cc/libraries/github.com/adafruit/RTClib-2.1.1.zip | ||
| + | https://downloads.arduino.cc/libraries/github.com/adafruit/RTClib-2.1.1.zip | ||
| + | https://downloads.arduino.cc/libraries/github.com/adafruit/ | ||
| − | Code | + | ==Code== |
#include <Wire.h> | #include <Wire.h> | ||
Latest revision as of 12:46, 24 April 2023
Meterial yang diperlukan dalam tutorial kali ini adalah:
- Arduino
- LCD 16×2
- I2C LCD
- RTC DS1307
- Library untuk I2C download disini atau disini.
- Library untuk RTC DS1307 download disini.
Library
https://github.com/Erriez/ErriezDS1307/archive/refs/heads/master.zip https://downloads.arduino.cc/libraries/github.com/adafruit/RTClib-2.1.1.zip https://downloads.arduino.cc/libraries/github.com/adafruit/RTClib-2.1.1.zip https://downloads.arduino.cc/libraries/github.com/adafruit/RTClib-2.1.1.zip https://downloads.arduino.cc/libraries/github.com/adafruit/
Code
#include <Wire.h>
#include <RTClib.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
const unsigned int BUTTON_PIN = 7;
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
RTC_DS1307 RTC;
char daysOfTheWeek[7][12] = {"Ming", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"};
char bulan[12][12] = {"Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"};
void setup() {
// put your setup code here, to run once:
Wire.begin();
RTC.begin();
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT);
lcd.begin();
//lcd.print("Belajar I2C LCD");
if (! RTC.begin()) {
Serial.println("RTC tidak ditemukan");
while (1);
}
if (! RTC.isrunning()) {
Serial.println("RTC tidak jalan!");
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
// Mengatur tanggal dan waktu sesuai dengan waktu code di compile
//RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
DateTime now = RTC.now();
lcd.setCursor(0,0);
lcd.print("Pukul : ");
if(now.hour()<10){
lcd.print("0");}
lcd.print(now.hour(), DEC);
lcd.print(':');
if(now.minute()<10){
lcd.print("0");}
lcd.print(now.minute(), DEC);
lcd.print(':');
if(now.second()<10){
lcd.print("0");}
lcd.print(now.second(), DEC);
lcd.setCursor(0,1);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(",");
lcd.print(now.day(), DEC);
lcd.print('/');
//lcd.print(now.month(), DEC);
lcd.print(bulan[now.month()]);
lcd.print('/');
lcd.print(now.year(), DEC);
delay(1000);
}