#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
byte LT[8] = { B00111, B01111, B11111, B11111, B11111, B11111, B11111, B11111};
byte UB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000};
byte RT[8] = { B11100, B11110, B11111, B11111, B11111, B11111, B11111, B11111};
byte LL[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B01111, B00111};
byte LB[8] = { B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111};
byte LR[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11110, B11100};
byte MB[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111};
RTC_DS1307 rtc;
char szTime[9]; // mm:ss\0
char szsecond[4]; // ss
char daysOfTheWeek[7][12] = {"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"};
char month2str [13][12] = {" ", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"};
void setup()
{
lcd.init(); // initialize the lcd
lcd.createChar(0, LT);
lcd.createChar(1, UB);
lcd.createChar(2, RT);
lcd.createChar(3, LL);
lcd.createChar(4, LB);
lcd.createChar(5, LR);
lcd.createChar(6, MB);
lcd.backlight();
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
lcd.clear();
}
void loop()
{
DateTime now = rtc.now();
static uint32_t lastTime = 0; // millis() memory
static bool flasher = false; // seconds passing flasher
if (millis() - lastTime >= 1000)
{
lastTime = millis();
displayNumber(0, now.hour());
displayNumber(7, now.minute());
bool f = !flasher;
flasher = !flasher;
if (flasher==true){
lcd.setCursor(6, 0); lcd.write(4);
lcd.setCursor(6, 1); lcd.write(1);
}
else{
lcd.setCursor(6, 0); lcd.write(254);
lcd.setCursor(6, 1); lcd.write(254);
}
lcd.setCursor(14, 1); lcd.print(now.second());
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(month2str[now.month()]);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
}
void printNumber(int val,int col) {
if ( val >= 10) {
printDigits(val / 10, col);
printDigits(val % 10, col + 3);
}
else {
printDigits(val, col+3);
}
}
void displayNumber(int col, int waktu) {
// lcd.clear();
printNumber(waktu,col);
}
void custom0(int x) { lcd.setCursor(x, 0); lcd.write(0); lcd.write(1); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5);}
void custom1(int x) { lcd.setCursor(x, 0); lcd.write(1); lcd.write(2); lcd.print(" "); lcd.setCursor(x, 1); lcd.write(4); lcd.write(255); lcd.write(4);}
void custom2(int x) { lcd.setCursor(x, 0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(4);}
void custom3(int x) { lcd.setCursor(x, 0); lcd.write(6); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5);}
void custom4(int x) { lcd.setCursor(x, 0); lcd.write(3); lcd.write(4); lcd.write(255); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(255);}
void custom5(int x) { lcd.setCursor(x, 0); lcd.write(3); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(4); lcd.write(4); lcd.write(5);}
void custom6(int x) { lcd.setCursor(x, 0); lcd.write(0); lcd.write(6); lcd.write(6); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5);}
void custom7(int x) { lcd.setCursor(x, 0); lcd.write(1); lcd.write(1); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(255);}
void custom8(int x) { lcd.setCursor(x, 0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.write(3); lcd.write(4); lcd.write(5);}
void custom9(int x) { lcd.setCursor(x, 0); lcd.write(0); lcd.write(6); lcd.write(2); lcd.setCursor(x, 1); lcd.print(" "); lcd.print(" "); lcd.write(255);}
void printDigits(int digits, int x) {
// utility function for digital clock display: prints preceding colon and leading 0
switch (digits) {
case 0:
custom0(x);
break;
case 1:
custom1(x);
break;
case 2:
custom2(x);
break;
case 3:
custom3(x);
break;
case 4:
custom4(x);
break;
case 5:
custom5(x);
break;
case 6:
custom6(x);
break;
case 7:
custom7(x);
break;
case 8:
custom8(x);
break;
case 9:
custom9(x);
break;
}
}