Binary clock with RGB Panel

In our Blog post of 17. June we have already a real-time clock with our Nano V3connected.

Some customers have it rebuilt, and had in essence 2 questions:

1. How do I get the colon to Blink?

2. How are you supposed to make out of something a Binary clock?

 

Both of these questions, I would like to answer in our today's Blog post.

 

Finished Binary clock display

 

For the Binary display, I use the popular AZ-Derlivery U-64 LED Panel with 64 WS2812b RGB LEDs.

 

Otherwise, we need a capacitor (1000 µF) and a resistor (220 Ω)

As always if we with the WS2812b LEDs work: these are very Bright, but also very much current. One of the 64 LEDs draw at full brightness, up to 50mA. The Nano, however, can deliver a maximum of 200mA. Who operates the Panel, so with low brightness or with an external power supply, risking his own health and that of his fellow men.

 

We take the circuit from the earlier post, and expand this. DIN on the RGB Panel is connected to 220Ω resistor to the Pin D6 on the Arduino connected.

For the power supply I recommend a 5V power supply with 5A. Vir connect the Plus Pole of the power supply to the +5V Pin of the panel, and the Minus Pole of the power supply to the GND Pin of the panel. Then we bridge note the +5V and GND Pins of the panel with the 1000µF capacitor (polarity!).

In order for the Panel to work, we must connect GND to the Panel with the GND Pin of the Arduino.

Now is a good time to go in order to test whether the clock and the display.

If everything works as expected, and no magic Smoke arises, have we done everything right.

 

Next, the Sketsch comes. For this purpose, I used the Sketch from the earlier Blog post advanced:

 

//////////////////////////////////////////////////////////////////////////////////////////////////////c!p/
// Binary clock with the RTC module and the 8x8 RGB LED Matrix
//
// extension of the real-time clock from the AZ-Delivery Blog post 
// https://www.az-delivery.de/blogs/azdelivery-blog-fur-arduino-und-raspberry-pi/echtzeituhr-mit-display-am-nano-v3
//
// Used modified code from npowley https://codebender.cc/sketch:241472#NeoPixel%20Binary%20Clock.ino
// Used modified code from http://www.pjrc.com/teensy/td_libs_DS1307RTC.html 
//////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <Arduino.h>

#include <TM1637Display.h> // for 4bit 7 segment display
#include <Wire.h> // to the RTC for reading
#define RTC_I2C_ADDRESS 0x68 // I2C address of the RTC DS3231
#include <FastLED.h> // to the LED Panel control (https://github.com/FastLED/FastLED)
 
#define CLK 2 // Arduino Pin D2 as a CLK (RTC) 
#define DIO 3 // Ardiono Pin D3 as DIO (RTC)
#define NUM_LEDS 64 // number of LEDs
#define DATA_PIN 6 // Data Pin D6 on the Nano for the U-64 LED Panel
#define HourColor Red // color for hours
#define minute color Green // color for minutes
#define second color Blue // color for seconds
#define HourNeutral Black // Off-color for hours
#define minute neutral Black // Off Color for minutes
#define second neutral Black // Off-color for seconds
#define LEDDimLevel 8 // Hall of the LEDs. In the case of higher please Panel on which the Nano with 5v supply.

TM1637Display display(CLK, DIO); // 7-Segment display
uint8_t dots = 0b10000000; // double-punk of the 7-Segment display.

uint8_t * bcdToDec( uint8_t val )
{    return (uint8_t) ((val / 16 * 10) + (val % 16));
}

int pause = 190;
 
int hour,,minute,,second;

CRGB leds,[NUM_LEDS]; // Array for LED Panel to create a

void setup(){   Wire.begin();   Serial.begin(9600);   display.setBrightness(0x0a);  // brightness 7-Segment display   FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds,, NUM_LEDS); // LED Panel Array to fill
}
 
void loop(){    Wire.begintrans mission(RTC_I2C_ADDRESS); //Establish the connection to the address 0x68    Wire and.write(0);    Wire.final mission();    Wire.request from(RTC_I2C_ADDRESS, 7);      second = * bcdToDec(Wire.read() & 0x7f);    minute = * bcdToDec(Wire.read());     hour = * bcdToDec(Wire.read() & 0x3f);           Serial.print(hour);      Serial.print(":");      Serial.print(minute);      Serial.print(":");      Serial.println(second,);      if ((second % 2) == 0){ // 7-Segment-display-separator ":" on or off          dots = 0b11111111;      }      else {         dots = 0b00000000;      }      display.showNumberDecEx(stunde, dots, true, 2, 0);      display.showNumberDec(minute, true, 2, 2);        FastLED.clear();    LEDS.setBrightness(LEDDimLevel);      if (stunde > 12) { // von 24h Format auf 12h format        stunde = stunde -12;      }      displayHour(stunde); // Stunde binär anzeigen      displayMinute(minute); // Minute binär anzeigen      displaySecond(sekunde); // Sekunde binär anzeigen     delay(pause);
}

void displayHour(byte Stunde){   for (int h = 0; h <= 3; h++) // count from most right Bit (0) to 4th Bit (3)
//for (int h = 3; h >= 0; h--)   {     if (bitRead(stunde, h) == 1){ // Read the single Bits from right to left and if there is a !1!, bring the LED up       leds[55 - h] = CRGB::HourColor; // show the color defined at the top of this sketch       leds[63 - h] = CRGB::HourColor; // show the color defined at the top of this sketch     }     else     {       leds[55 - h] = CRGB::HourNeutral; // if the LED is not used, take it down or to a different color. See top of the ketch       leds[63 - h] = CRGB::HourNeutral; // if the LED is not used, take it down or to a different color. See top of the ketch     }   }   FastLED.show(); // Show the LEDs
}
 
void displayMinute(byte Minute){   for (int m = 0; m <= 5; m++){     if (bitRead(Minute, m) == 1){       leds[31 - m] = CRGB::MinuteColor; // Start at the 1st LED for the minutes (4) and add the Minute-Bit       leds[39 - m] = CRGB::MinuteColor; // Start at the 1st LED for the minutes (4) and add the Minute-Bit     }     else     {       leds[31 - m] = CRGB::MinuteNeutral;       leds[39 - m] = CRGB::MinuteNeutral;     }   }   FastLED.show();
}
 
void displaySecond(byte Sekunde){   for (int s = 0; s <= 5; s++){     if (bitRead(Sekunde, s) == 1){       leds[7 - s] = CRGB::SecondColor; // Start at the 1st LED for the seconds (10) and add the Seconds-Bits       leds[15 - s] = CRGB::SecondColor; // Start at the 1st LED for the seconds (10) and add the Seconds-Bits     }     else     {       leds[7 - s] = CRGB::SecondNeutral;       leds[15 - s] = CRGB::SecondNeutral;     }   }   FastLED.show();
}

 

 Nun sieht man zwar, je nach aktueller Uhrzeit, mehr oder weniger viele bunte LEDs aufleuchten, aber die anzeige ich auch für Binär-Erfahrene Menschen nicht immer leicht zu entziffern.

Daher habe ich eine kleine Schablone zum Ausdrucken erstellt. Diese kann über folgendem Dropbox-Link heruntergeladen werden: https://www.dropbox.com/s/nr2kuth73zbqka1/bin%20uhr.svg?dl=0

 

 

 

 

Wie heißt es so schön: "Es gibt 10 Arten von Menschen. Die, die Binärcode verstehen und die, die ihn nicht verstehen."

Daher sollte eine Binäre Uhr in keinem Informatik-Klassenzimmer fehlen.

 

Natürlich gibt es noch einiges zu tun. Der Sketch könnte noch an einigen Stellen optimiert werden. Mir gefällt es z.B. nicht dass die RGB LEDs bei jedem durchlauf flackern.

Außerdem wollte jemand einen Temperatursensor, und einen Zeit-gesteuerten Servo, und einen DCF Empfänger, und einen Buzzer, und einen Larson-Scanner für die ungenutzten LEDs, und, und ...

 

Aber das soll es für heute erstmal gewesen sein. 

Wir freuen uns auf Ihr Kommentare.

Bis zum nächsten Beitrag von AZ-Delivery, Ihrem Experten für Mikroelektronik!

 

For arduinoProjekte für fortgeschrittene

1 comment

Richard

Richard

Hallo,
habe ein max7219 Led Matrix, damit funktioniert der Code leider nicht.
5Anschlüsse:
VCC, GND, DIN, CS, CLK
Könnten sie mir den Code so umschreiben damit es auch mit dem max7219 funktioniert?
Danke im voraus für ihre Bemühungen.

Liebe Grüße
Richard

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN