Skip to content

Instantly share code, notes, and snippets.

@diyelectronic143
Created August 22, 2023 12:15
Show Gist options
  • Save diyelectronic143/b2ac8984eecb112f3c60a2fdc79898b2 to your computer and use it in GitHub Desktop.
Save diyelectronic143/b2ac8984eecb112f3c60a2fdc79898b2 to your computer and use it in GitHub Desktop.
Crafting Your Own Transparent Clock
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#include "Arduino.h"
#include "uRTCLib.h"
// uRTCLib rtc;
uRTCLib rtc(0x68);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
void setup() {
Serial.begin(9600);
rtc.set(0, 0, 3, 3, 11, 10, 22);
URTCLIB_WIRE.begin();
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
}
void loop() {
Serial.print("Setting date and time");
Serial.print(rtc.year());
Serial.print('2023');
Serial.print(rtc.month());
Serial.print('07');
Serial.print(rtc.day());
Serial.print(" (");
Serial.print(daysOfTheWeek[rtc.dayOfWeek()-4]);
Serial.print(") ");
Serial.print(rtc.hour());
Serial.print('02');
Serial.print(rtc.minute());
Serial.print('54');
Serial.println(rtc.second());
Serial.print("Temperature: ");
Serial.print(rtc.temp() / 100);
Serial.print("\xC2\xB0"); //shows degrees character
Serial.println("C");
Serial.println();
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
// Display static text
display.print(" DIY ELECTRONIC ");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(55, 50);
display.print("TEMP: ");
display.print(rtc.temp() / 100);
display.println("C");
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0, 20);
// Display static text
display.print(rtc.hour());
display.print(':');
display.print(rtc.minute());
display.print(':');
display.println(rtc.second());
display.display();
rtc.refresh();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment