// Simulates a 6 digit Nixie Clock.
// The Nixie tube and driver (K155ID1 or 74141) are
// simulated by a custom chip and 7 segment display.
#include "RTClib.h"
#include <FastLED.h>
#define DATA_PIN 8 // Pin connected to DS of 74HC595
#define LATCH_PIN 9 // Pin connected to STCP of 74HC595
#define CLOCK_PIN 10 // Pin connected to SHCP of 74HC595
#define LED_PIN 7 // Led Data Pin
#define NUM_LEDS 6 // The number of leds
byte data[3] = { 0, 0, 0}; // hh, mm, ss
int currentSecond;
int hue = 0;
RTC_DS1307 rtc;
CRGB leds[NUM_LEDS];
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
randomSeed(analogRead(0));
}
void loop() {
DateTime now = rtc.now();
int second = now.second();
int minute = now.minute();
int hour = now.hour();
//Serial.println(second);
if (second != currentSecond) {
currentSecond = second;
setSecond(second / 10, second % 10);
setMinute(minute / 10, minute % 10);
setHour(hour / 10, hour % 10);
shiftOutData();
hue += 2;
}
fill_rainbow( leds, NUM_LEDS, hue, 6);
//fill_solid(leds, NUM_LEDS, CRGB(44, 233, 243));
//leds[0] = CRGB::Red;
//leds[1] = CRGB(79, 239, 199);
//leds[2] = CRGB(238, 51, 188);
FastLED.show();
/*
int rnd = random(100);
setSecond(rnd / 10, rnd % 10);
rnd = random(100);
setMinute(rnd / 10, rnd % 10);
rnd = random(100);
setHour(rnd / 10, rnd % 10);
shiftOutData();
delay(300);
*/
}
void setSecond(int dec1, int dec0) {
data[2] = setByte(dec1, dec0);
}
void setMinute(int dec1, int dec0) {
data[1] = setByte(dec1, dec0);
}
void setHour(int dec1, int dec0) {
data[0] = setByte(dec1, dec0);
}
byte setByte(int dec1, int dec0) {
return (dec1 << 4) | dec0;
}
void shiftOutData() {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, data[2]);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, data[1]);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, data[0]);
digitalWrite(LATCH_PIN, HIGH);
}
Minutes
Hours
Seconds