//arduino clock by blogduino 30/09/2022
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
//fonts https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts#step-2
#include <Fonts/FreeSerif9pt7b.h>
#include <RTClib.h>
#define i2c_Address 0x3c
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS3231 rtc;
int day;
int month;
int year;
int temperature;
String time;
void setup(void) {
// put your setup code here, to run once:
Serial.begin(115200);
delay(250);
display.begin(i2c_Address, true);
// SETUP RTC MODULE
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (true);
}
// automatically sets the RTC to the date & time on PC this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
time.reserve(1); // to avoid fragmenting memory when using String
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
time = "";
time += now.hour();
time += ':';
time += now.minute();
time += ':';
time += now.second();
day = now.day();
month = now.month();
year = now.year();
temperature = rtc.getTemperature();
if(millis()%1000==0){
display.clearDisplay();
display.setTextSize(2);
//display.setFont(&FreeSerif9pt7b);
display.setTextColor(SH110X_WHITE);
display.setCursor(20, 5);
display.println(time);
//Original Font
display.setFont();
display.setCursor(45, 25);
display.println(temperature);
display.setCursor(70, 25);
display.println('c');
display.setTextSize(2);
display.setCursor(8, 45);
display.println(day);
display.setCursor(51,45);
display.println(month);
display.setCursor(79,45);
display.println(year);
display.setTextSize(3);
display.setCursor(34,40);
display.println('/');
display.setCursor(62,40);
display.println('/');
display.display();
}
}
Comments
Please log in or sign up to comment.