Electrodude
Published

Building a Smart RGB Clock with Arduino Nano

Building a Smart RGB Clock with Arduino Nano and Custom WS2812B Segment Displays

BeginnerFull instructions provided2 hours368

Story

Read more

Code

WS212B CLOCK CODE

C/C++
This ocde is for diy ws2812b clock
// CODE BY " ELECTRO DUDE "
// Youtube - https://youtu.be/9cX18g8DiFk


#include <FastLED.h>
#include <DS3231.h>
#include <Wire.h>


#define NUM_LEDS 56
#define DATA_PIN 6


CRGB leds[NUM_LEDS];
DS3231 rtc;


const int TOTAL_SEGMENTS = 4;
const int LEDS_PER_SEGMENT = 14;
const int DISPLAY_SEGMENT[] = {14 * 3, 14 * 2, 0, 14};
const int DISPLAY_NUMBER[][14] = {
  {true, true, true, true, true, true, true, true, true, true, true, true, false, false}, // 0 Number
  {false, false, true, true, true, true, false, false, false, false, false, false, false, false}, // 1 Number
  {true, true, true, true, false, false, true, true, true, true, false, false, true, true}, // 2 Number
  {true, true, true, true, true, true, true, true, false, false, false, false, true, true}, // 3 Number
  {false, false, true, true, true, true, false, false, false, false, true, true, true, true}, // 4 Number
  {true, true, false, false, true, true, true, true, false, false, true, true, true, true}, // 5 Number
  {true, true, false, false, true, true, true, true, true, true, true, true, true, true}, // 6 Number
  {true, true, true, true, true, true, false, false, false, false, false, false, false, false}, // 7 Number
  {true, true, true, true, true, true, true, true, true, true, true, true, true, true}, // 8 Number
  {true, true, true, true, true, true, true, true, false, false, true, true, true, true}, // 9 Number
};


CRGB yellowColor = CRGB(255, 248, 9);


void setup() {
  Serial.begin(9600);
  Serial.println("Starting execution");
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(30);
  Wire.begin();
  // Lines can be uncommented to set the date and time
  rtc.setHour(00);     //  24hr format
 rtc.setMinute(15);   // Set the minute
}


void loop() {
  bool h12, pm;
  int hour = rtc.getHour(h12, pm);
  int minute = rtc.getMinute();


  int hourFirstDigit = hour / 10;
  int hourSecondDigit = hour % 10;


  int minuteFirstDigit = minute / 10;
  int minuteSecondDigit = minute % 10;


  int totalDelay = 0;


  while (totalDelay < 10000) {
    FastLED.clear();
    displayNumber(2, hourFirstDigit, yellowColor);
    displayNumber(3, hourSecondDigit, yellowColor);
    displayNumber(1, minuteFirstDigit, yellowColor);
    displayNumber(0, minuteSecondDigit, yellowColor);
    FastLED.show();


    delay(10);
    totalDelay += 10;
  }
}


void displayNumber(int segment, int number, CRGB color) {
  for (int j = 0; j < LEDS_PER_SEGMENT; j++) {
    if (DISPLAY_NUMBER[number][j]) {
      leds[DISPLAY_SEGMENT[segment] + j] = color;
    }
  }
}

Credits

Electrodude

Electrodude

4 projects β€’ 5 followers
Hey, I am Electro dude 😎. In this channel, I make videos on DIY projects, electric & electronic projects & also review some products.

Comments