Binary clock RGB rainbow scheme

Hi guys!

Bit of background:
I love buiding all kinds of clocks and calendars.
Back in the early 2000’s I built my first binary clock using a lot of 74LS93’s and a hand full of diodes. Nowadays things have gotten a lot easier with very accessible microcontrollers as our beloved Arduino.

Current situation:
I’m currently working on a new version of a binary clock using a chain of WS2812 leds on a strip forming a matrix, an RTC module and an UNO. As diffusers I’m using pingpong balls inspired by mr_fid's beautiful design. As mr_fid doesn't use addressable leds, I had to write a code from scratch. It may not be the most efficient, but I've got things running correctly now. At the moment the LED's are displaying binary digits in a white color.

Desired situation:
In order to get the maximum visual effect I would like to switch between two kind of visual effects using a switch that pulls a pin either high or low.

  1. HIGH = The matrix of leds to display a slow (horizontal) rainbow fade when the binary digits light up (like in the video below).
  2. LOW = All the LED's displaying white.

My programming skills are not fantastic, but I can manage. However at this moment of time I’m approaching an area beyond my knowledge and would herefore like to seek some guidance. I would like to know how to embed this rainbow scheme in my code and how to toggle between it.





#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_NeoPixel.h>

#define LED_PIN 8
#define LED_COUNT 20

RTC_DS1307 rtc;

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

// Definition of the LED layout
const int columnHeights[] = { 2, 4, 3, 4, 3, 4 };

void setup() {
  Serial.begin(9600);
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1)
      ;
  }

  if (!rtc.isrunning()) {
    Serial.println("RTC is not running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  strip.begin();
  strip.show();  // Initialize all pixels to 'off'
}

void loop() {
  DateTime now = rtc.now();

  // Get hours, minutes, and seconds
  int hours = now.hour();
  int minutes = now.minute();
  int seconds = now.second();

  // Display hours in binary
  displayBinary(hours / 10, 0, true);     // First column
  displayBinary(hours % 10, 2, false);    // Second column
  displayBinary(minutes / 10, 6, true);   // Third column
  displayBinary(minutes % 10, 9, false);  // Fourth column
  displayBinary(seconds / 10, 13, true);  // Fifth column
  displayBinary(seconds % 10, 16, false); // Sixth column

  //debug (to check the time in the serial monitor)
  Serial.print(now.hour());
  Serial.print(now.minute());
  Serial.print(now.second());


  delay(1000);  // Update every second
}

// Function to display a decimal number in binary on my LED matrix
void displayBinary(int value, int startLED, bool invert) {
  int height = columnHeights[startLED / 3];
  for (int i = 0; i < height; i++) {
    int index = invert ? height - 1 - i : i;
    if (value & (1 << index)) {
      strip.setPixelColor(startLED + i, 255, 255, 255);  // LEDs on 
    } else {
      strip.setPixelColor(startLED + i, 0, 0, 0);  // LEDs off
    }
  }
  strip.show();
}

Say if it is just doing that, or telling time also, in which case say more about how the effect mixes with telling time.

What o'clock does it say in the photograph of the monochrome ping pong balls?

I did see

  delay(1000);  // Update every second

instead, you could condition running the display part on whether the seconds had changed since the previous time from the RTC..

I am a relentless delay() eliminator, and this may actually be useful when you do get the modes working.

I can't the rest of the code just now, but did see that.

a7

Say if it is just doing that, or telling time also, in which case say more about how the effect mixes with telling time.

Thank you for your contribution!
My idea was indeed to mix the rainbow effect with telling time. So for example the rainbow effect runs 'silently' in the background and once a digit is commanded, it would display the corrosponding color. Does my explanation make any sense?

I did see

  delay(1000);  // Update every second

instead, you could condition running the display part on whether the seconds had changed since the previous time from the RTC..

I am a relentless delay() eliminator, and this may actually be useful when you do get the modes working.

I was hesitant using the delay as well. Was thinking to add some momentary pushbuttons for time correction, but that won't be possible if a delay is used. I will try to sort that out using a condition you suggested.

What o'clock does it say in the photograph of the monochrome ping pong balls?

Thats exactly what I like so much about these mysterious kind of clocks!
It's: 21:08:22 but the the third column from the right displays the binary upside down in this picture. I was still debugging it at the time.

21:07:22

Not quite. Aren't digita being commanded, as you put it, alla time because it's a clock?

As for the delay thing, in the loop() something like

static byte lastSeconds

// get the time like you do every loop who cares

  if (seconds != lastSeconds) {

// stuff you wanna do every new second goes here, or set a flag for doing or not doing stuff later

    lastSeconds = seconds;    // so you can detect the next change
  }

HTH

a7

@xfpd
Haha, ever so many thanks for your valuable contribution to my topic. :joy:

static byte lastSeconds

// get the time like you do every loop who cares

if (seconds != lastSeconds) {

// stuff you wanna do every new second goes here, or set a flag for doing or not doing stuff later

lastSeconds = seconds;    // so you can detect the next change

}

Hey thanks! I’ll be fiddling with this to get that delay() out of the way. I’ll keep you posted.

Not quite. Aren't digita being commanded, as you put it, alla time because it's a clock?

Excuse my crude explanation. I was hoping something would be possible to combine the rainbow scheme with the telling of time. Maybe it would be a better idea to assign a separate color to each column. would you recon that to be feasible?

tl;dr: I write this last, after visiting your links to other projects. The time I spended on them makes me think you shouldn't have any trouble with this new clock idea… other than deciding what it's going to do.

I shoulda taken your links first, no worries.

Believe it or not, I am not really very creative.

Take some time and read around these fora, or google the raw internets themselves, and see the breadth and depth of what ppl accomplish with so-called smart LEDs and puny microprocessor boards. With or without RTCs.

Or trust me when I say just about anything that you can think up that might play out on your little canvas that is 22 fully adjustable "pixels" can probably be done, if you leave out blinking Morse code messages that announce chess moves or answers to deep philosophical conundra.

They don't say "limited only by your imagination" for nothing. :expressionless:

If I had a copy, I might have it doing something cool that occasional came to a stop for long enough for a person to read the time.

Imagine every pixel blinking at a different rate coming in and out of phase one to another, or a few others until the ones that should be illuminated "now" are all the ones that just turned on and the process freezes for eight seconds.

Add colour, so the dancing is wild but white is where they end up at least once every forty-five seconds or so.

But that's me. You probably have ideas, maybe already you could describe more of where you wanna go with this.

This text will be hidden

I like the ping pong lamps, I've done that and it works well. Cheap ping pong balls will show less like pure spheres, you may have discovered. And good ones are spendy, or at least they seemed so when I was working with them, or more accurately not working with them but using the ones from Dollar Land.

a7

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.