
================================== SOURCE CODE ==================================
#include "Time.h"
#include "RTClib.h"
#include "EEPROM.h"
#include "Wire.h"
#include "DS3231.h"
#include "IRremote.h"
#define LATCH 2
#define CLK 3
#define DATA 4
RTC_DS1307 RTC;
DS3231 rtc(SDA, SCL);
byte dot1[11] = {0xFD, 0x51 , 0xBB, 0xDB, 0x57, 0xCF, 0xEF, 0x59, 0xFF, 0xDF};//baru
byte digit1[11] = {0xFC, 0x50 , 0xBA, 0xDA, 0x56, 0xCE, 0xEE, 0x58, 0xFE, 0xDE};//baru
byte digit2[11] = {0x7E, 0x0C, 0xB6, 0x9E, 0xCC, 0xDA, 0xFA, 0x0E, 0xFE, 0xDE}; //lama
byte dot2[11] = {0x7F, 0x0D, 0xB7, 0x9F, 0xCD, 0xDB, 0xFB, 0x0F, 0xFF, 0xDF}; //lama
byte digit[11]= {0x7E, 0x0C, 0xB6, 0x9E, 0xCC, 0xDA, 0xFA, 0x0E, 0xFE, 0xDE};//digit1,5
int Jam, Menit, Detik, temp, umid, Tanggal, Bulan, Tahun;
int satuanJam, satuanMenit, satuanDetik;
int puluhanJam, puluhanMenit, puluhanDetik;
int satuanTemp, puluhanTemp;
int satuanTanggal, satuanBulan;
int puluhanTanggal, puluhanBulan;
int ribuanTahun, ratusanTahun, puluhanTahun, satuanTahun;
int hoursButton1 = A3;
int minsButton1 = A1;
int hoursButton2 = A2;
int minsButton2 = A0;
unsigned long ti;
int RECV_PIN = 11;
String IRButton1 = "1FEB04F";//+JAM
String IRButton2 = "1FEF00F";//-JAM
String IRButton3 = "1FE708F";//+MENIT
String IRButton4 = "1FE9867";//-MENIT
byte value;
byte value2;
byte value3;
IRrecv irrecv(RECV_PIN);
decode_results results;
String BUTTONPRESSED;
int button1 = 0;
int button2 = 0;
int button3 = 0;
int button4 = 0;
int led1 = 8;
int led2 = 9;
void setup() {
pinMode(LATCH, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(hoursButton1, INPUT_PULLUP);
pinMode(minsButton1, INPUT_PULLUP);
pinMode(hoursButton2, INPUT_PULLUP);
pinMode(minsButton2, INPUT_PULLUP);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
if (! RTC.isrunning()) {
RTC.adjust(DateTime(__DATE__, __TIME__));
}
Wire.beginTransmission(0X68);
Wire.write(0x07);
Wire.write(0x10);
Wire.endTransmission();
Wire.begin();
rtc.begin();
}
void loop() {
DateTime now = RTC.now();
value = EEPROM.read(0);
value2 = EEPROM.read(1);
value3 = EEPROM.read(2);
Jam = now.hour();
Menit = now.minute();
Detik = now.second();
Tanggal = now.day();
Bulan = now.month();
Tahun = now.year();
temp= rtc.getTemp();
satuanTemp = temp % 10;
puluhanTemp = temp / 10;
satuanJam = Jam % 10;
puluhanJam = Jam / 10;
satuanMenit = Menit % 10;
puluhanMenit = Menit / 10;
satuanDetik = Detik % 10;
puluhanDetik = Detik / 10;
satuanTanggal = Tanggal % 10;
puluhanTanggal = Tanggal / 10;
satuanBulan = Bulan % 10;
puluhanBulan = Bulan / 10;
satuanTahun = Tahun % 10;
puluhanTahun = Tahun / 10;
ribuanTahun = Tahun / 1000;
ratusanTahun = Tahun % 1000 / 100;
puluhanTahun = Tahun % 1000 / 10;
satuanTahun = Tahun % 10;
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
BUTTONPRESSED = String(results.value, HEX);
BUTTONPRESSED.toUpperCase();
Serial.print("BUTTONPRESSED ");
Serial.println(BUTTONPRESSED);
if (BUTTONPRESSED == IRButton1) {
Jam++;
Detik = 00;
if (Jam > 23) {
Jam = 00;
}
updateRTC();
}
if (BUTTONPRESSED == IRButton2) {
Jam--;
Detik = 00;
if (Jam < 00) {
Jam = 23;
}
updateRTC();
}
if (BUTTONPRESSED == IRButton3) {
Menit++;
Detik = 00;
if (Menit > 59) {
Menit = 00;
}
updateRTC();
}
if (BUTTONPRESSED == IRButton4) {
Menit--;
Detik = 00;
if (Menit < 00) {
Menit = 59;
}
updateRTC();
}
irrecv.resume(); // Receive the next value
}
if (digitalRead(hoursButton1) == LOW) {
delay(200);
Jam++;
Detik = 00;
if (Jam > 23) {
Jam = 00;
}
updateRTC();
}
if (digitalRead(minsButton1) == LOW) {
delay(200);
Menit++;
Detik = 00;
if (Menit > 59) {
Menit = 00;
}
updateRTC();
}
if (digitalRead(hoursButton2) == LOW) {
delay(200);
Jam--;
Detik = 00;
if (Jam < 00) {
Jam = 23;
}
updateRTC();
}
if (digitalRead(minsButton2) == LOW) {
delay(200);
Menit--;
Detik = 00;
if (Menit < 00) {
Menit = 59;
}
updateRTC();
}
Tampil();
}
byte decToBcd(byte val) {
return ( (val / 10 * 16) + (val % 10) );
}
byte bcdToDec(byte val) {
return ( (val / 16 * 10) + (val % 16) );
}
void updateRTC() {
Wire.beginTransmission(104);
Wire.write(0);
Wire.write(decToBcd(Detik));
Wire.write(decToBcd(Menit));
Wire.write(decToBcd(Jam));
Wire.endTransmission();
}
void mati() {
digitalWrite(CLK, LOW);
digitalWrite(LATCH, LOW);
}
void Tampil(){
digitalWrite(LATCH, LOW);
//1,5 Inch
shiftOut(DATA, CLK, MSBFIRST, ~B01110010);
shiftOut(DATA, CLK, MSBFIRST, ~B11000110);
shiftOut(DATA, CLK, MSBFIRST, ~digit2[satuanTemp]);
shiftOut(DATA, CLK, MSBFIRST, ~digit2[puluhanTemp]);
//3 Inch
shiftOut(DATA, CLK, MSBFIRST, digit2[satuanBulan]);
shiftOut(DATA, CLK, MSBFIRST, digit2[puluhanBulan]);
shiftOut(DATA, CLK, MSBFIRST, digit2[satuanTanggal]);
shiftOut(DATA, CLK, MSBFIRST, digit2[puluhanTanggal]);
//2,3 Inch
shiftOut(DATA, CLK, MSBFIRST, digit1[satuanDetik]);
shiftOut(DATA, CLK, MSBFIRST, digit1[puluhanDetik]);
shiftOut(DATA, CLK, MSBFIRST, digit1[satuanMenit]);
shiftOut(DATA, CLK, MSBFIRST, digit1[puluhanMenit]);
shiftOut(DATA, CLK, MSBFIRST, digit1[satuanJam]);
shiftOut(DATA, CLK, MSBFIRST, digit1[puluhanJam]);
digitalWrite(LATCH, HIGH);
}
Video
1 comment
Sir. Can I get circuit diagrem?Please
Post a Comment