LAGSILVA
Published © CC BY-NC-ND

Ternary Digital Clock with Arduino

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

BeginnerShowcase (no instructions)30 minutes9,868
Ternary Digital Clock with Arduino

Things used in this project

Story

Read more

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

Code

Ternary_Digital_Clock_with_RTC_V1_3.ino

Arduino
/*
  Project:  Ternary Digital Clock with RTC
  Hardware: Arduino UNO-R3 / Strip LED
  Author:   LAGSILVA
  Revision: 1.3
  Date:     26.Jan.2019
  License:  CC BY-NC-ND 4.0
            (Attribution-NonCommercial-NoDerivatives 4.0 International)
*/

#include <Time.h>                  // Time library
#include <TimeLib.h>
#include <Wire.h>                  // Library for DS1307RTC - Pins of Arduino UNO: A4 (SDA), A5 (SCL)
#include <DS1307RTC.h>             // Library for Real Time Clock
#define DS1307_I2C_ADDRESS 0x68    // This is the I2C address (RTC)
#include <Adafruit_NeoPixel.h>

#define ledPin 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 pos, cor[3];
byte dezH = 0, uniH = 0, dezM = 0, uniM = 0;
byte hora = 0, minuto = 0;


void setup() {

  pinMode(ledPin, OUTPUT);

  setSyncProvider(RTC.get); // Reading RTC (Real Time Clock)
  setSyncInterval(60);      // Set the number of seconds between re-sync

  //setTime(16, 11, 00, 26, 01, 2019);   // Setting Time and Date
  //RTC.set(now());                      // Setting RTC Time


  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() {

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

}

Credits

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

Comments