Project tutorial

Scrambled Digits Clock with Alarm © CC BY-NC-ND

This is a clock with its digits out of order. Within the apparent chaos is a beautiful order! Very easy to use including an alarm clock!

  • 499 views
  • 2 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

This is a clock with its digits out of order.

Within the apparent chaos is a beautiful order!

Very simple use and intuitive reading, including an adjustable alarm for a buzzer or just a visual alert.

Using only three push buttons is possible to setup the time and alarm.

Note:

The internal clock of Arduino causes a delay of some seconds running during an hour, but RTC (Real Time Clock) is not used in this case because it is part of the fun to set the time on the clock by watching the changes in the sequence of digits.

Considering the playful purpose of this project, this is not an important issue.

Video

1. Components

2. Setting of Time and Alarm

There are 3 buttons for the setup of time and alarm:

  • Mode Button: navigation thru modes

(T)Time setting: Hour & Minute

(TA)Time Alarm setting: Hour & Minute

(A)Alarm On/Off

  • Hour Button:

- Adjust the Hour in Modes (T) and (TA).

- Setup of Visual Alarm to On/Off in Mode (A).

  • Minute Button:

- Adjust the Minute in Modes (T) and (TA).

- Setup of Sound Alarm to On/Off in Mode (A) only when the Alarm is On.

3. Coding

In order for the clock to be readable, it is necessary to keep the default reading sequence from left to right, top to bottom.

To do this, the code's main logic divides the hour and minute into their tens and units to fetch them from the scrambled digit matrix.

By following this criterion, time reading becomes easier.

The LED matrix is divided into three main areas:

  • Top Left: Used to display the digits (tens and units) of hours.
  • Top Right: Used to display the digits (tens and units) of minutes.
  • Bottom: Used to display the digits (tens and units) of seconds.

Note: As a personal preference, I have removed "zeros of tens" from numbers less than 10 for readability.

Code

Scrambled_Clock_V1_1.inoArduino
Code for Arduino UNO
/*
   Project:   Scrambled Digits Clock with Alarm
   Author:    LAGSILVA
   Hardware:  Arduino UNO-R3, 8x8 LED Matrix MAX72XX
   Date:      11.Ago.2019
   Revision:  1.1
   License:   CC BY-NC-ND 4.0
              (Attribution-NonCommercial-NoDerivatives 4.0 International)
*/

#include <LedControl.h>                 // Library for LED Display - MAX72XX
#include <Time.h>                       // Time library
#include <TimeLib.h>

// Global Variables
byte pinBuzzer = 3;
byte pinHora = 10, pinMinuto = 9, pinModo = 8;

// Digits for Paper Template V1.1.A
String digH = "89206735149350846712";
String digM = "54897310260928547316";
String digS = "42783650194510692873";

byte hh, mm, ss, lastS = 0;
byte hAlarme, mAlarme, alarmeOn = 0, buzzerOn = 0;
byte btnHora, btnMinuto, btnModo, modo = 0;
byte rowTS, colTS, rowUS, colUS;

/*
  Pin numbers of Arduino to be connected into MAX72XX (LED Matrix controlled by MAX72XX)
  pin 5 is connected to the DataIn (DIN)
  pin 6 is connected to LOAD (CS)
  pin 7 is connected to the CLK (CLK)
*/

LedControl lc = LedControl(5, 7, 6, 1); // LedControl(int dataPin, int clkPin, int csPin, int numDevices)


void setup() {

  pinMode(pinHora, INPUT_PULLUP);
  pinMode(pinMinuto, INPUT_PULLUP);
  pinMode(pinModo, INPUT_PULLUP);

  // Setup of Display "0"
  lc.shutdown(0, false);                // Wakeup Display "0"
  lc.setIntensity(0, 5);                // Set the Brightness of Display (0 to 15)
  lc.clearDisplay(0);                   // Clear Display "0" (Hour)

}


void loop() {

  hh = hour();
  mm = minute();
  ss = second();

  btnHora = digitalRead(pinHora);
  btnMinuto = digitalRead(pinMinuto);
  btnModo = digitalRead(pinModo);

  if (btnModo == LOW) {
    modo = (modo + 1) % 4;              // Mode: 0 (Display the Time) / 1 (T = Set Time) / 2 (A = Set Alarm) / 3 (Alarm On-Off)
    lc.clearDisplay(0);
    delay(150);
  }

  if (btnHora == LOW && modo == 1) {    // Setup of Hour
    adjustTime(3600);
    adjustTime(-second());
    hh = hour();
    mm = minute();
    lc.clearDisplay(0);
    plotTime(hh, mm, 0);
    delay(150);
  }

  if (btnMinuto == LOW && modo == 1) {  // Setup of Minute
    adjustTime(60);
    adjustTime(-second());
    hh = hour();
    mm = minute();
    lc.clearDisplay(0);
    plotTime(hh, mm, 0);
    delay(150);
  }

  if (btnHora == LOW && modo == 2) {    // Setup of Alarm Hour
    hAlarme = (hAlarme + 1) % 24;
    lc.clearDisplay(0);
    plotTime(hAlarme, mAlarme, 0);
    delay(150);
  }

  if (btnMinuto == LOW && modo == 2) {  // Setup of Alarm Minute
    mAlarme = (mAlarme + 1) % 60;
    lc.clearDisplay(0);
    plotTime(hAlarme, mAlarme, 0);
    delay(150);
  }

  if (btnHora == LOW  && modo == 3) {   // Buzzer Alarm On-Off
    alarmeOn = !alarmeOn;
    buzzerOn = 0;
    plotTime(hAlarme, mAlarme, 0);
    lc.setLed(0, 1, 7, alarmeOn);
    lc.setLed(0, 0, 7, buzzerOn);
    delay(150);
  }

  if (btnMinuto == LOW && alarmeOn == 1 && modo == 3) {   // Only Display Alarm On-Off
    buzzerOn = !buzzerOn;
    plotTime(hAlarme, mAlarme, 0);
    lc.setLed(0, 1, 7, alarmeOn);
    lc.setLed(0, 0, 7, buzzerOn);
    delay(150);
  }

  if (modo == 0) {                          // Mode: Display Time
    plotTime(hh, mm, ss);
    lc.setLed(0, 7, 7, false);              // Mode T
    lc.setLed(0, 6, 7, false);              // Mode A
    lc.setLed(0, 1, 7, alarmeOn);           // Mode Alarm
    lc.setLed(0, 0, 7, buzzerOn);           // Mode Buzzer
  }

  if (modo == 1) {                          // Mode: Set Time
    plotTime(hh, mm, 0);
    lc.setLed(0, 7, 7, true);
    lc.setLed(0, 6, 7, false);
    lc.setLed(0, 1, 7, false);
    lc.setLed(0, 0, 7, false);
  }

  if (modo == 2) {                          // Mode: Set Alarm Time
    plotTime(hAlarme, mAlarme, 0);
    lc.setLed(0, 7, 7, true);
    lc.setLed(0, 6, 7, true);
    lc.setLed(0, 1, 7, false);
    lc.setLed(0, 0, 7, false);
  }

  if (modo == 3) {                          // Mode: Set Alarm On-Off
    plotTime(hAlarme, mAlarme, 0);
    lc.setLed(0, 7, 7, false);
    lc.setLed(0, 6, 7, true);
    lc.setLed(0, 1, 7, alarmeOn);
    lc.setLed(0, 0, 7, buzzerOn);
  }

  if (hh == hAlarme && mm == mAlarme && ss <= 5 && alarmeOn == 1) {   // Check Alarm Time
    alarme();
  }

}


void plotTime(byte hora, byte minuto, byte segundo) {

  byte unitH, unitM, unitS, tenH, tenM, tenS;
  byte row, col, pos;

  unitH = hora % 10;
  tenH = hora / 10;
  unitM = minuto % 10;
  tenM = minuto / 10;
  unitS = segundo % 10;
  tenS = segundo / 10;

  if (segundo == 0 && segundo != lastS) {
    lc.clearDisplay(0);
  }

  if (segundo != lastS) {
    lc.setLed(0, rowTS, colTS, false);
    lc.setLed(0, rowUS, colUS, false);
    lastS = segundo;
  }

  //Plot Hour Tens
  pos = 0;
  if (tenH > 0) {
    pos = digH.indexOf(String(tenH), 0);
    row = 7 - pos % 4;
    col = pos / 4;
    lc.setLed(0, row, col, true);
    pos = pos + 1;
  }

  //Plot Hour Units
  pos = digH.indexOf(String(unitH), pos);
  row = 7 - pos % 4;
  col = pos / 4;
  lc.setLed(0, row, col, true);

  //Plot Minute Tens
  pos = 0;
  if (tenM > 0) {
    pos = digM.indexOf(String(tenM), pos);
    row = 3 - pos % 4;
    col = pos / 4;
    lc.setLed(0, row, col, true);
    pos = pos + 1;
  }

  //Plot Minute Units
  pos = digM.indexOf(String(unitM), pos);
  row = 3 - pos % 4;
  col = pos / 4;
  lc.setLed(0, row, col, true);

  //Plot Second Tens
  pos = 0;
  if (tenS > 0) {
    pos = digS.indexOf(String(tenS), pos);
    rowTS = 7 - pos % 8;
    colTS = pos / 8 + 5;
    if (colTS == 7) {
      rowTS = rowTS - 2;
    }
    lc.setLed(0, rowTS, colTS, true);
    pos = pos + 1;
  }

  //Plot Second Units
  pos = digS.indexOf(String(unitS), pos);
  rowUS = 7 - pos % 8;
  colUS = pos / 8 + 5;
  if (colUS == 7) {
    rowUS = rowUS - 2;
  }
  lc.setLed(0, rowUS, colUS, true);

}


void alarme() {

  lc.clearDisplay(0);
  while (btnHora == HIGH && btnMinuto == HIGH) {
    btnHora = digitalRead(pinHora);
    btnMinuto = digitalRead(pinMinuto);
    btnModo = digitalRead(pinModo);
    for (byte k = 0; k <= 7; k++) {
      lc.setRow(0, k, 255);
      delay(25);
    }
    if (buzzerOn == 1) {
      analogWrite(pinBuzzer, 230);
    }
    for (byte k = 0; k <= 7; k++) {
      lc.setRow(0, k, 0);
      delay(25);
    }
    if (buzzerOn == 1) {
      analogWrite(pinBuzzer, 180);
    }
  }
  analogWrite(3, 255);
  lc.clearDisplay(0);

}

Custom parts and enclosures

Paper Template for Scrambled Clock
Paper template for LED matrix of Scrambled Digits Clock

Schematics

Schematic - Scrambled Clock
Breadboard Schematic for Scrambled Clock

Comments

Similar projects you might like

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

Project tutorial by LAGSILVA

  • 2,951 views
  • 3 comments
  • 11 respects

Analog Clock with LED Matrix and Arduino

Project tutorial by LAGSILVA

  • 15,316 views
  • 14 comments
  • 56 respects

Ternary Digital Clock with Arduino

Project tutorial by LAGSILVA

  • 5,209 views
  • 6 comments
  • 13 respects

Simple Clock with LED Matrix

Project tutorial by LAGSILVA

  • 4,526 views
  • 9 comments
  • 15 respects

Stopwatch and Lap Timer with Arduino

Project tutorial by LAGSILVA

  • 19,476 views
  • 17 comments
  • 38 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 17,782 views
  • 20 comments
  • 65 respects
Add projectSign up / Login