garysat
Published © GPL3+

Arduino Analog/Digital Clock with Nokia 5110

An analog/digital clock using Arduino Nano, DS1307 & Nokia 5110.

BeginnerShowcase (no instructions)9,017
Arduino Analog/Digital Clock with Nokia 5110

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Nokia 5110 128 X 64 display
×1
Real Time Clock (RTC)
Real Time Clock (RTC)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

analog/digital clock using nokia 5110

Code

Analog_digital clock

Arduino
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;


// Software SPI (slower updates, more flexible pin options):
// pin 8 - Serial clock out (SCLK)
// pin 9 - Serial data out (DIN)
// pin 10- Data/Command select (D/C)
// pin 12- LCD chip select (CS)
// pin 11- LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(8, 9, 10, 12, 11);


void setup() {
  // put your setup code here, to run once:
  display.begin();
  display.setContrast(50);
  display.clearDisplay();
  display.display(); // show splashscreen

  Serial.begin(9600);
 if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  
  }
}

void loop() {
  DateTime now = rtc.now();
  int h=now.hour();
  int m=now.minute();
  int s=now.second();

  for(int i=0;i<10;i++)
    {
    drawClock(h,m,s);
    delay(1000);
    s++;
    if(s>=60) m++;
    s=s%60;
    if(m>=60) h++;
    m=m%60;
    h=h%24;
    }
}

void drawClock(int h, int m, int s)
{
const int r=15;
const double rot=-M_PI/2;
double x,y,x0,y0,anglerad;
  
  display.clearDisplay();
 //display.drawPixel(0,0,BLACK);
  display.drawPixel(24,24,BLACK);
  display.drawCircle(24,24,r,BLACK);
  for(int i=0;i<12;i++)
    {
    int angled=360/12*i;
    anglerad=2*M_PI/12*i+rot;
    x=r*cos(anglerad);
    y=r*sin(anglerad);
    x0=(r-3)*cos(anglerad);
    y0=(r-3)*sin(anglerad);
   Serial.print(h);
   Serial.print(":");
   Serial.print(m);
   Serial.print(":");
   Serial.print(s);
  
    Serial.println("");

    display.drawLine(24+x0,24+y0,24+x,24+y,BLACK);
    }

  // hour
   display.setCursor(19,1);
   display.print("12");
   display.setCursor(2,20);
   display.print("9");
   display.setCursor(43,20);
   display.print("3");
   display.setCursor(21,41);
   display.print("6");


  
  
  
   display.setCursor(54,4);
   display.print("TIME");
   display.setCursor(54,14);
 
   display.print(h);
   display.print(":");
   display.print(m);

  anglerad=2*M_PI/12*(h%12)+2*M_PI/12/60*m+rot;
  x=(r-7)*cos(anglerad);
  y=(r-7)*sin(anglerad);
  x0=0;
  y0=0;
  display.drawLine(24+x0,24+y0,24+x,24+y,BLACK);
  
  // minute
   anglerad=2*M_PI/60*m+rot;
  x=(r-5)*cos(anglerad);
  y=(r-5)*sin(anglerad);
  x0=0;
  y0=0;
  display.drawLine(24+x0,24+y0,24+x,24+y,BLACK);

  // second
  display.setCursor(63,22);
 
  display.print(s);
  
   anglerad=2*M_PI/60*s+rot;
  x=(r-2)*cos(anglerad);
  y=(r-2)*sin(anglerad);
  x0=0;
  y0=0;
  display.drawLine(24+x0,24+y0,24+x,24+y,BLACK);

 
  display.display();  
}

Credits

garysat
4 projects • 36 followers
Contact
Thanks to Robert Ulbrich.

Comments

Please log in or sign up to comment.