kelly77
Created August 6, 2022 © GPL3+

OLED clock

useing 0.96 inch oled display and ds1307 and arduino uno/nano you can make a 24hr clock.

BeginnerProtip12
OLED clock

Things used in this project

Story

Read more

Schematics

image_2022-08-06_152058101_swDUewnlwC.png

Code

Untitled file

C/C++
Go to a new sketch paste the code below uplode it then go to exampel then scroll down to ds1307 click on it then uplodthat code and it will coppy the same time as on your comuter.
   #include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Time.h>
#include <DS1307RTC.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup()
{
  
  //Serial.begin(9600);
   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
   //display.display();
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.clearDisplay();
  
  }

  void loop()
  {
    display.clearDisplay();
    tmElements_t tm;
    if(RTC.read(tm)){
      display.clearDisplay();
    display.setTextSize(3);
    display.setTextColor(WHITE);
    display.setCursor(5,8);
    print2digits(tm.Hour);
    display.write(':');
    print2digits(tm.Minute);
    display.setTextSize(2);
    display.setCursor(100,8);
     print2digits(tm.Second);
    display.setCursor(16,45);
    display.setTextSize(2);
     display.print(tm.Day);
    display.write('/');
    display.print(tm.Month);
    display.write('/');
    display.print(tmYearToCalendar(tm.Year));
    display.display();
    
    }
    else
    {
      if(RTC.chipPresent())
      {
        display.setTextSize(1);
  display.setTextColor(WHITE);
        display.print("DS1307 stopped,run set time");
        display.display();
        }
        else
        {
          display.setTextSize(1);
  display.setTextColor(WHITE);
        display.print("DS1307 read error,check circuit");
        display.display();
          }
          delay(9000);
      }
      delay(1000);
     
  }

    void print2digits(int number) {
  if (number >= 0 && number < 10) {
    display.write('0');
    // display.display();
  }
  display.print(number);
   //display.display();
  //display.println();
}

Credits

kelly77
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.