Jam Digtal Arduino + 7 Segment
ichibot store//Program Jam Digital
#include <Wire.h>
#include <RTClib.h>
#include <TM1637Display.h>
#define CLK 3
#define DIO 2
RTC_DS3231 rtc;
TM1637Display display(CLK, DIO); // Menggunakan pin DIO pada D2 dan CLK pada D3
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
display.setBrightness(0x0a); // Sesuaikan kecerahan layar TM1637 (0x00 - 0x0f)
}
void loop() {
DateTime now = rtc.now();
int hours = now.hour();
int minutes = now.minute();
// Tampilkan jam digital pada TM1637
display.showNumberDecEx((hours * 100) + minutes, 0b11100000, true);
delay(1000); // Tunggu 1 detik
display.clear();
}
//program set waktu RTC
/*
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
setRTC(); // Panggil fungsi setRTC untuk mengatur waktu
}
}
void loop() {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
setRTC(); // Panggil fungsi setRTC untuk mengatur waktu
}
void setRTC() {
// Atur waktu sesuai keinginan Anda: tahun, bulan, hari, jam, menit, detik
DateTime setTime(2024, 3, 6, 10, 55, 0);
rtc.adjust(setTime);
Serial.println("Waktu telah diatur!");
}
*/