Project tutorial
Ternary Digital Clock with Arduino

Ternary Digital Clock with Arduino © CC BY-NC-ND

This is an original ternary digital clock running with Arduino! It's very simple and unlike anything you've ever seen!

  • 3,736 views
  • 5 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

1. Introduction

Probably you have seen many binary clocks, but it is not so usual a ternary digital clock.

This project introduce an original ternary digital clock running with Arduino, very simple to be assembled and unlike anything you've ever seen!

Ternary clocks represent the hour and minute in Ternary Numeral System what means the numbers are powers of 3 (or base 3).

As comparison, binary numbers the base is 2 and in decimal system, the base is 10.

Maybe it sounds a little complicated, but the reading and use of ternary clock is very simple.

Let's see the project and I hope you enjoy it!

Video

2. Numeral Systems

Numbers are everywhere in our lives and the decimal numeral system is what we use everyday.

In fact there are many different numeral base such as binary, octal or hexa. Specially for computing, binary is the primary reference.

It is easy to transform any number in different base with a minimum of simple calculations.

Note: If you want more information, I suggest you read the article Numbers in Different Bases of Oxford College.

The ternary numeral consists basically in numbers written with 0, 1 or 2.

For example:

Decimal: 15 = 1 * 10 + 5 * 1

Ternary: 0120 = 0 * 27 + 1 * 9 + 2 * 3 + 0 * 1

The following table shows the conversion from decimal (0 to 9) to ternary.

The strategy of the program applies two different colors representing the digits 1 and 2 of ternary numbers.

0:No color

1: Green

2: Red

These colors are used on RGB LEDs to see the hours and minutes as shown on pictures below.

3. Clock Setup

For the setup of hour and minute there are two push buttons to be used:

-Leftpush button: operation mode setting

  • Mode 0: regular clock operation
  • Mode 1: Tens of hour (upper left LED in red)
  • Mode 2: Units of hour (upper right LED in red)
  • Mode 3: Tens of minute (upper left LED in green)
  • Mode 4: Units of minute (upper right LED in green)

- Right push button: time setting (hour/minute)

According to the selected mode, the LED displays numbers from 0 to 9 in blue.

Press the button until the correct number is displayed, and then press the Mode button to move to the next setting.

Note: The reference "zero" is printed as "3" marked crosswise.

4. Clock Reading

The design proposal using 12 LED NeoPixels arranged in a circle remind us a traditional clock.

The clock is divided into four partitions with 3 LEDs each:

  • Tens of hour: displayed at the upper right partition
  • Units of hour: displayed at the lower right partition
  • Tens of minute: displayed at the lower left partition
  • Units of minute: displayed at the upper left partition

Reading are based on which LEDs are on and what are their colors.

Over each LED there is a printed number in the paper template: 1, 3, 9

These numbers must be add to totalize the number of hour or minute.

-Meaning of LED colors:

  • Green: the number is what is printed.
  • Red: the number is twice the printed.

-Example:

Time is 20:47 hs.

  • Fisrt quarter: 1 is Red = 2 x 1 = 2
  • Second quarter: all LEDs off = 0
  • Third quarter: 1 and 3 are Green = (1 + 3) = 4
  • Fourth quarter: 1 is Green and 3 is Red = 1 + (2 x 3) = 7

Code

Ternary_Digital_Clock_V1_0.inoArduino
Code for Arduino UNO R3
/*
  Project:  Ternary Digital Clock
  Author:   LAGSILVA
  Revision: 1.0
  Date:     05.Jan.2019
*/

#include <Time.h>       // Time library
#include <TimeLib.h>

#include <Adafruit_NeoPixel.h>

#define ledPin 5
#define timeKey 6
#define modeKey 7

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, ledPin, NEO_GRB + NEO_KHZ800);

byte mode = 0, pos, cor[3];
byte dezH = 0, uniH = 0, dezM = 0, uniM = 0;
byte hora = 0, minuto = 0;

byte delayKey = 200;

void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(modeKey, INPUT_PULLUP);
  pinMode(timeKey, INPUT_PULLUP);

  strip.setBrightness(10);  // Setting brightness of LED ring
  strip.begin();            // Initialize all pixels to 'off'

  for (byte k = 0; k < 12; k++) {
    strip.setPixelColor((k + 10) % 12, 128, 128, 0);
    strip.show();
    delay(500);
  }

  delay(2000);

  strip.clear();
  strip.show();

}


void loop() {

  // Setting Mode

  if (digitalRead(modeKey) == LOW) {

    mode = (mode + 1) % 5;

    strip.clear();

    if (mode == 1) { //dezH Mode
      // strip.setPixelColor(n, red, green, blue);
      strip.setPixelColor(8, 255, 0, 0);
      strip.setPixelColor((dezH + 10) % 12, 0, 0, 255);
    }

    if (mode == 2) { //uniH Mode
      strip.setPixelColor(9, 255, 0, 0);
      strip.setPixelColor((uniH + 10) % 12, 0, 0, 255);
    }

    if (mode == 3) { //dezM Mode
      strip.setPixelColor(8, 0, 255, 0);
      strip.setPixelColor((dezM + 10) % 12, 0, 0, 255);
    }

    if (mode == 4) { //uniM Mode
      strip.setPixelColor(9, 0, 255, 0);
      strip.setPixelColor((uniM + 10) % 12, 0, 0, 255);
    }

    strip.show();

    delay(delayKey);

  }

  // Setting Hour & Minute

  if (digitalRead(timeKey) == LOW) {

    if (mode == 1) {  // Set "tens" of hour
      dezH = (dezH + 1) % 3;
      //setTime(hours, minutes, seconds, days, months, years);
      setTime(dezH * 10 + uniH, dezM * 10 + uniM, 0, 0, 0, 0);
      strip.clear();
      strip.setPixelColor(8, 255, 0, 0);
      strip.setPixelColor((dezH + 10) % 12, 0, 0, 255);
      strip.show();
    }

    if (mode == 2 && dezH < 2) { // Set "units" of hour
      uniH = (uniH + 1) % 10;
      setTime(dezH * 10 + uniH, dezM * 10 + uniM, 0, 0, 0, 0);
      strip.clear();
      strip.setPixelColor(9, 255, 0, 0);
      strip.setPixelColor((uniH + 10) % 12, 0, 0, 255);
      strip.show();
    }

    if (mode == 2 && dezH >= 2) { // Set "units" of hour
      uniH = (uniH + 1) % 4;
      setTime(dezH * 10 + uniH, dezM * 10 + uniM, 0, 0, 0, 0);
      strip.clear();
      strip.setPixelColor(9, 255, 0, 0);
      strip.setPixelColor((uniH + 10) % 12, 0, 0, 255);
      strip.show();
    }

    if (mode == 3) {  // Set "tens" of minute
      dezM = (dezM + 1) % 6;
      setTime(dezH * 10 + uniH, dezM * 10 + uniM, 0, 0, 0, 0);
      strip.clear();
      strip.setPixelColor(8, 0, 255, 0);
      strip.setPixelColor((dezM + 10) % 12, 0, 0, 255);
      strip.show();
    }

    if (mode == 4) {  // Set "units" of minute
      uniM = (uniM + 1) % 10;
      setTime(dezH * 10 + uniH, dezM * 10 + uniM, 0, 0, 0, 0);
      strip.clear();
      strip.setPixelColor(9, 0, 255, 0);
      strip.setPixelColor((uniM + 10) % 12, 0, 0, 255);
      strip.show();
    }

    delay(delayKey);

  }

  // Clock Mode

  if (mode == 0) {

    strip.clear();

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

    dezH = hora / 10;
    uniH = hora % 10;
    dezM = minuto / 10;
    uniM = minuto % 10;


    // Print Tens of Hour

    cor[0] = (dezH / 1 ) % 3;
    cor[1] = (dezH / 3 ) % 3;
    cor[2] = (dezH / 9 ) % 3;

    for (pos = 0; pos <= 2; pos++) {

      if (cor[pos] == 1) { // Green color
        strip.setPixelColor(pos + 9, 0, 255, 0);
      }

      if (cor[pos] == 2) { // Red Color
        strip.setPixelColor(pos + 9, 255, 0, 0);
      }

    }


    // Print Units of Hour

    cor[0] = (uniH / 1 ) % 3;
    cor[1] = (uniH / 3 ) % 3;
    cor[2] = (uniH / 9 ) % 3;

    for (pos = 0; pos <= 2; pos++) {

      if (cor[pos] == 1) { // Green color
        strip.setPixelColor(pos, 0, 255, 0);
      }

      if (cor[pos] == 2) { // Red Color
        strip.setPixelColor(pos, 255, 0, 0);
      }

    }


    // Print Tens of Minute

    cor[0] = (dezM / 1 ) % 3;
    cor[1] = (dezM / 3 ) % 3;
    cor[2] = (dezM / 9 ) % 3;

    for (pos = 0; pos <= 2; pos++) {

      if (cor[pos] == 1) { // Green color
        strip.setPixelColor(pos + 3, 0, 255, 0);
      }

      if (cor[pos] == 2) { // Red Color
        strip.setPixelColor(pos + 3, 255, 0, 0);
      }

    }


    // Print Units of Minute

    cor[0] = (uniM / 1 ) % 3;
    cor[1] = (uniM / 3 ) % 3;
    cor[2] = (uniM / 9 ) % 3;

    for (pos = 0; pos <= 2; pos++) {

      if (cor[pos] == 1) { // Green color
        strip.setPixelColor(pos + 6, 0, 255, 0);
      }

      if (cor[pos] == 2) { // Red Color
        strip.setPixelColor(pos + 6, 255, 0, 0);
      }

    }

    strip.show();

  }

}

Custom parts and enclosures

Paper Template
Paper template to be printed to cover the LED ring of Ternary Clock

Schematics

Bread Board Diagram
Bread Board Diagram for Ternary Digital Clock

Comments

Similar projects you might like

(Updated) Digital Clock w/ Mirrored Display for UNO-R3 & 101

Project tutorial by LAGSILVA

  • 1,059 views
  • 0 comments
  • 3 respects

4-Stroke Digital Clock With Arduino

Project showcase by LAGSILVA

  • 11,405 views
  • 11 comments
  • 39 respects

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

Project showcase by LAGSILVA

  • 1,957 views
  • 3 comments
  • 9 respects

Digital And Binary Clock With Two LED Matrix And RTC

Project tutorial by LAGSILVA

  • 6,315 views
  • 11 comments
  • 26 respects

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 97,344 views
  • 24 comments
  • 84 respects

Digital Clock with Mirrored Display Driven by Accelerometers

Project showcase by LAGSILVA

  • 14,590 views
  • 1 comment
  • 38 respects
Add projectSign up / Login