LAGSILVA
Published © CC BY-NC-ND

Analog Clock with LED Matrix and Arduino

This is my project about an Analog Clock on a LED matrix and Arduino.

BeginnerShowcase (no instructions)1 hour28,032

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Maxim Integrated LED Matrix with MAX7219
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Paper Template to cover the LED Matrix

Story

Read more

Custom parts and enclosures

Paper Template

Paper Template to be print and put over the LED Matrix

Code

Analog_Clock_with_LED_Matrix_V1_1.ino

Arduino
/*
  Project:  Analog Clock with LED Matrix
  Author:   LAGSILVA
  Hardware: Arduino UNO R3 / LED Matrix with MAX72XX
  Date:     26.Jul.2017
  Revision: 1.1
  License:  CC BY-NC-ND 4.0
            (Attribution-NonCommercial-NoDerivatives 4.0 International)
*/

#include <LedControl.h>
#include <Time.h>
#include <TimeLib.h>

/*
  ***** Pin numbers for LedControl *****
  pin 10 is connected to the DataIn
  pin 08 is connected to the CLK
  pin 09 is connected to LOAD / CS
  We have only a single MAX72XX.
*/
LedControl lc = LedControl(10, 8, 9, 1);

byte xRef = 4; // Reference Row
byte yRef = 3; // Reference Collunm
byte mm1, mm5, hora, minuto;
byte ultMinuto = 10, ultHora = 10;
byte horaPin = 7, minutoPin = 6;
boolean ajustaHora = true, ajustaMinuto = true;
float pi = 3.1415927, xHH, yHH, xMM1, yMM1, xMM5, yMM5;


void setup() {

  pinMode(horaPin, INPUT_PULLUP);
  pinMode(minutoPin, INPUT_PULLUP);

  /* Wakeup call for MAX72XX */
  lc.shutdown(0, false);

  /* Set the brightness to a medium values */
  lc.setIntensity(0, 2);

}


void loop() {

  // Setup of Hours & Minutes
  ajustaHora = digitalRead(horaPin);
  ajustaMinuto = digitalRead(minutoPin);

  if (!ajustaHora) {
    adjustTime(3600);
  }

  if (!ajustaMinuto) {
    adjustTime(60);
  }

  hora = hour();
  minuto = minute();

  if (minuto != ultMinuto || hora != ultHora) {

    ultMinuto = minuto;
    ultHora = hora;
    lc.clearDisplay(0);

    // Minutes in steps of 5 (range of 0 to 55)
    mm5 = minuto / 5 * 5;

    //Minutes (1 to 4)
    mm1 = minuto % 5;

    // AM period
    if (hora >= 0 && hora <= 11) lc.setLed(0, xRef + 1, yRef, true);

    // PM period
    if (hora >= 12 && hora <= 23)lc.setLed(0, xRef - 1, yRef, true);

    // Coordinates for Hours & Minutes (steps of 5)
    xHH = round(-cos(hora * pi / 6) * 2) + xRef;
    yHH = round(sin(hora * pi / 6) * 2) + yRef;
    lc.setLed(0, xHH, yHH, true);

    xMM5 = round(-cos(mm5 * pi / 30) * 3.1) + xRef;
    yMM5 = round(sin(mm5 * pi / 30) * 3.1) + yRef;
    lc.setLed(0, xMM5, yMM5, true);

    //Coordinates for Minutes (1 to 4)
    yMM1 = yRef + 4;
    xMM1 = (mm1 - 1) * 2 + xRef - 3;
    if (mm1 > 0) lc.setLed(0, xMM1, yMM1, true);

  }

  // Center LED Blinking
  if (ajustaHora && ajustaMinuto) {
    lc.setLed(0, xRef, yRef, true);
    delay(200);
    lc.setLed(0, xRef, yRef, false);
    delay(800);
  }
  else delay(250);

}

Credits

LAGSILVA

LAGSILVA

7 projects • 340 followers
Mechanical Engineer in automotive industry since 1989. Coding and Arduino are my hobbies.

Comments