Project showcase

# Analog Clock with LED Matrix and Arduino © CC BY-NC-ND

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

• 23,407 views
• 84 respects

## Components and supplies

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

## Necessary tools and machines

 Paper Template to cover the LED Matrix

## Apps and online services

 Arduino IDE

### Introduction

LED matrix with MAX7219 are very versatile and can be used in several projects with Arduino.

In this case, I used it to simulate an analog clock without its hands, with very interesting results. The hours and minutes are placed around the center of matrix giving a familiar look of analog clocks. The code I have developed applies a little of trigonometry (sine and cosine) to calculate the coordinates of hours and minutes to be shown into LED matrix. With that I saved many lines of coding.

The assembly is very simple using few components and you will have no problems to work on it.

Let's do it!

### Material List

The material you need is shown in the following list:

• Arduino UNO R3
• Module of LED Matrix with MAX7219 (Maxim Integrated)
• Tactile Push Buttons (02 x)
• Jumper Wires
• Paper template to cover the LED Matrix (see attached file for printing)

Note: This project uses the Arduino internal clock. It is not so accurate as an external RTC (Real Time Clock), but for the purposes of this project, it works very well.

### Schematic

The schematic is attached and you should follow it closely for the jumpers connections.

### Setup

After starting, the default time shown is 00:00 hs.

For adjustments there are only two tactile buttons to perform the setup of time:

• Setup of Hours
• Setup of Minutes

Just keep it pressed for adjustments.

The hours are shown in the display by numbers between 1 and 12. The minutes are shown by numbers between 0 and 55 in steps of 5 minutes.

In the last column of display is shown the fractional minutes from 1 to 4 that must be added to the minutes shown in the main template of clock.

In the middle of display, there is an LED blinking each second and there are also two LEDs for AM and PM indication.

## Code

##### Analog_Clock_with_LED_Matrix_V1_1.inoArduino
```/*
Project:  Analog Clock with LED Matrix
Author:   LAGSILVA
Hardware: Arduino UNO R3 / LED Matrix with MAX72XX
Date:     26.Jul.2017
Revision: 1.1
*/

#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

if (!ajustaHora) {
}

if (!ajustaMinuto) {
}

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);

}

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

}
```

## Custom parts and enclosures

Paper Template to be print and put over the LED Matrix

#### Author

##### LAGSILVA
• 26 projects
• 311 followers

July 28, 2017

#### Members who respect this project

and 76 others

See similar projects
you might like

#### Amazing Binary Clock using LED Matrix Module

Project showcase by LAGSILVA

• 14,584 views
• 67 respects

#### Tiny Calendar and Clock Featuring Moon Phase in a LED Matrix

Project showcase by LAGSILVA

• 9,449 views
• 40 respects

#### Digital And Binary Clock With Two LED Matrix And RTC

Project showcase by LAGSILVA

• 19,590 views
• 58 respects

#### Simple Clock with LED Matrix

Project showcase by LAGSILVA

• 13,313 views
• 33 respects

#### Digital & Binary Clock In 8 Digits x 7 Segments LED Display

Project showcase by LAGSILVA

• 6,204 views