#include "Arduino.h"
#include "uRTCLib.h"
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// uRTCLib rtc;
uRTCLib rtc(0x68);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup() {
Serial.begin(115200);
delay(3000); // wait for console opening
URTCLIB_WIRE.begin();
// Comment out below line once you set the date & time.
// Following line sets the RTC with an explicit date & time
// for example to set January 13 2022 at 12:56 you would call:
rtc.set(0, 5, 10, 6, 5, 1, 24);
// rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
// set day of week (1=Sunday, 7=Saturday)
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
}
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 2); // set position to display (x,y)
//perkenalan
oled.println("KELOMPOK 3");
oled.println("- Geosevi");
oled.println("- Kharisma Bunga");
oled.println("- Muhammad Daffi");
oled.display(); // display on OLED
delay(3000); // wait two seconds for initializing
}
void loop() {
rtc.refresh();
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 2); // set position to display (x,y)
oled.println();
oled.print("tanggal : ");
oled.print(rtc.year()); // set text
oled.print("/");
oled.print(rtc.month());
oled.print("/");
oled.print(rtc.day());
// waktu
oled.println();
oled.print("pukul : ");
oled.print(rtc.hour()); // set text
oled.print(":");
oled.print(rtc.minute());
oled.print(":");
oled.print(rtc.second());
//
oled.println();
oled.println();
oled.println("Have A Nice Day");
oled.display(); // display on OLED
rtc.refresh();
Serial.print("Current Date & Time: ");
Serial.print(rtc.year());
Serial.print('/');
Serial.print(rtc.month());
Serial.print('/');
Serial.print(rtc.day());
Serial.print(" (");
Serial.print(daysOfTheWeek[rtc.dayOfWeek()-1]);
Serial.print(") ");
Serial.print(rtc.hour());
Serial.print(':');
Serial.print(rtc.minute());
Serial.print(':');
Serial.println(rtc.second());
delay(1000);
}