#include <TimeLib.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2);
char *pasar[] ={"Wage ", "Kliwon", "Legi ", "Paing ", "Pon "};
char *hari[] ={"Kamis ", "Jumat ", "Sabtu ", "Minggu ", "Senin ", "Selasa", "Rabu "};
int maxday[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
byte p1[8] = {
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10,
0x10};
byte p2[8] = {
0x18,
0x18,
0x18,
0x18,
0x18,
0x18,
0x18,
0x18};
byte p3[8] = {
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C,
0x1C};
byte p4[8] = {
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E};
byte p5[8] = {
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F};
int detik=10;
int menit=19;
int jam=17;
int tanggal=28;
int bulan=6;
int tahun=2016;
int blinkState = LOW;
unsigned long timer1;
unsigned long timer2; //update detik1
int curX;
int curY;
int set=6;
void setup() {
// set up the LCD's number of columns and rows:
pinMode(A2,INPUT);
pinMode(A1,INPUT);
pinMode(A0,INPUT);
lcd.createChar(1, p1);
lcd.createChar(2, p2);
lcd.createChar(3, p3);
lcd.createChar(4, p4);
lcd.createChar(5, p5);
lcd.begin(16, 2);
loadanim();
// Print a message to the LCD.
setTime(jam, menit, detik, tanggal, bulan, tahun);
}
void loop() {
//variable here
unsigned long currentMillis = millis();
int t1 = digitalRead(A0); //tombol setting
int t2 = digitalRead(A1); // tombol Up
int t3 = digitalRead(A2); // tombol down
detik=second();
menit=minute();
jam=hour();
tanggal=day();
bulan=month();
tahun=year();
//tombol setting
if (t3 == HIGH){
set = set +1;
delay(250);
if (set > 6) {
set=0;
}
}
//setting waktu kedip kedip
if(currentMillis - timer1 > 300) {
timer1 = currentMillis;
if (blinkState == LOW){
blinkState = HIGH;
}
else {
blinkState = LOW;
}
}
//setting posisi kedip2
if (set == 0) {
curX = 0;
curY = 0;
if (t1 == HIGH){
tanggal = tanggal +1;
delay(100);
if (tanggal > maxday[bulan] ) {
tanggal=1;
}
}
if (t2 == HIGH){
tanggal = tanggal -1;
delay(100);
if (tanggal < 1 ) {
tanggal=maxday[bulan];
}
}
setTime(jam, menit, detik, tanggal, bulan, tahun);
}
if (set == 1) {
curX = 3;
curY = 0;
if (t1 == HIGH){
bulan = bulan +1;
delay(100);
if (bulan > 12 ) {
bulan=1;
}
}
if (t2 == HIGH){
bulan = bulan -1;
delay(100);
if (bulan < 1 ) {
bulan=12;
}
}
setTime(jam, menit, detik, tanggal, bulan, tahun);
}
if (set == 2) {
curX = 6;
curY = 0;
if (t1 == HIGH){
tahun = tahun +1;
delay(100);
if (tahun > 3000 ) {
tahun=2000;
}
}
if (t2 == HIGH){
tahun = tahun -1;
delay(100);
if (tahun < 2000 ) {
tahun=3000;
}
}
setTime(jam, menit, detik, tanggal, bulan, tahun);
}
if (set == 3) {
curX = 0;
curY = 1;
if (t1 == HIGH){
jam = jam +1;
delay(100);
if (jam > 23 ) {
jam=0;
}
}
if (t2 == HIGH){
jam = jam -1;
delay(100);
if (jam < 0 ) {
jam=23;
}
}
setTime(jam, menit, detik, tanggal, bulan, tahun);
}
if (set == 4) {
curX = 3;
curY = 1;
if (t1 == HIGH){
menit = menit +1;
delay(100);
if (menit > 59 ) {
menit=0;
}
}
if (t2 == HIGH){
menit = menit -1;
delay(100);
if (menit < 0 ) {
menit=59;
}
}
setTime(jam, menit, detik, tanggal, bulan, tahun);
}
if (set == 5) {
curX = 6;
curY = 1;
if (t1 == HIGH){
detik = detik +1;
delay(100);
if (detik > 59 ) {
detik=0;
}
}
if (t2 == HIGH){
detik = detik -1;
delay(100);
if (detik < 0 ) {
detik=59;
}
}
setTime(jam, menit, detik, tanggal, bulan, tahun);
}
if (blinkState == LOW) {
if (set != 6){
lcd.setCursor(curX,curY);
lcd.print(" ");
}
}
//tampilkan jam kalender
if (blinkState == HIGH) {
lcd.setCursor(0, 0);
if (tanggal < 10) lcd.print('0');
lcd.print(tanggal);
lcd.print("/");
if (bulan < 10) lcd.print('0');
lcd.print(bulan);
lcd.print("/");
lcd.print(tahun-2000); //tampilkan tahun dua digit saja
lcd.setCursor(0,1);
if (jam < 10) lcd.print('0');
lcd.print(jam);
lcd.print(":");
if (minute() < 10) lcd.print('0');
lcd.print(menit);
lcd.print(":");
if (second() < 10) lcd.print('0');
lcd.print(detik);
lcd.print(" ");
lcd.setCursor(10, 0);
lcd.print(hari[jumlahhari()%7]); //tampilkan Hari
lcd.setCursor(10, 1);
//lcd.write(0xC2);
lcd.print(pasar[jumlahhari()%5]); //Tampilkan Pasaran
}
// end //tampilkan jam kalender
}
// digunakan untuk menghitung hari pasaran
int jumlahhari(){
int d= day();
int m= month();
int y= year();
int hb[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
int ht = (y - 1970) * 365 - 1;
int hs = hb[m - 1] + d;
int kab = 0;
int i;
if(y % 4 == 0) {
if(m > 2) {
hs++;
}
}
for(i = 1970; i < y; i++) {
if(i % 4 == 0) {
kab++;
}
}
return (ht + hs + kab);
}
void loadanim(){
lcd.print(" LOADING");
lcd.setCursor(0,1);
for (int loadbar = 0; loadbar < 16; loadbar++) {
lcd.setCursor(loadbar,1);
lcd.setCursor(loadbar,1);
lcd.write(1);
delay(10);
lcd.setCursor(loadbar,1);
lcd.write(2);
delay(10);
lcd.setCursor(loadbar,1);
lcd.write(3);
delay(10);
lcd.setCursor(loadbar,1);
lcd.write(4);
delay(10);
lcd.setCursor(loadbar,1);
lcd.write(5);
delay(10);
}
delay(500);
lcd.clear();
}