#mikrocontroller2019
Published © CC BY

Decorative Hidden LED Clock

Yet another RGB LED ring clock...

BeginnerFull instructions provided1 hour1,648
Decorative Hidden LED Clock

Things used in this project

Hardware components

ESP-32 Dev Kit C
×1
Adafruit NeoPixel Ring - 12 x 5050 RGB LED with Integrated Drivers
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
RIBBA Frame, black
×1
One-cent-coin
×1
ESP32S
Espressif ESP32S
added just for tagging ... ;)
×1

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

ESP32 - 12 RGB LED ring clock with 'touch activation'

Code

ESP32 - 12bit RGB LED Ring Clock - Demo

Arduino
#include <WiFi.h>
#include <time.h>
#include <Adafruit_NeoPixel.h>

int hour;
int minute;
int second;
int displayCount;
int hourHand;
int minuteHand;
int secondHand;
int ledIndex;
int red;
int green;
int blue;

const char* ssid = "...";
const char* password = "...";
Adafruit_NeoPixel myLedRing;
bool touchDetected[10];

void connect() {
  WiFi.begin(ssid, password);
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
  };
}

bool wasTouchDetected(int pinIdx) {
  bool td = touchDetected[pinIdx];
  touchDetected[pinIdx] = false;
  return td;
}

void gotTouchT6() {
  touchDetected[6] = true;
}

struct tm* getTime(){
  time_t now = time(nullptr);
  return localtime(&now);
}



void setup() {
  touchAttachInterrupt(T6, gotTouchT6, 40);

  connect();
  configTime(3600, 3600, "pool.ntp.org");
  myLedRing = Adafruit_NeoPixel(12, 12, NEO_GRB + NEO_KHZ800);
  myLedRing.begin();
  myLedRing.show();
  hour = 0;
  minute = 0;
  second = 0;
  displayCount = 15;

}

void loop() {
  if (wasTouchDetected(6)) {
    displayCount = 30;
  }
  while (displayCount > 0) {
    hour = getTime()->tm_hour;
    minute = getTime()->tm_min;
    second = getTime()->tm_sec;
    hourHand = hour % 12;
    minuteHand = minute / 5;
    secondHand = second / 5;
    for (ledIndex = 0; ledIndex <= 11; ledIndex++) {
      red = 0 + (ledIndex == hourHand ? 128 - 32 * (minute / 15) : 0);
      green = 0 + (ledIndex == minuteHand ? 128 - 32 * (minute % 5) : 0);
      blue = 0 + (ledIndex == secondHand ? 128 - 32 * (second % 5) : 0);
      if (ledIndex == (hourHand + 1) % 12) {
        red = 32 * (minute / 15);
      }
      if (ledIndex == (minuteHand + 1) % 12) {
        green = 32 * (minute % 5);
      }
      if (ledIndex == (secondHand + 1) % 12) {
        blue = 32 * (second % 5);
      }
      myLedRing.setPixelColor(ledIndex, myLedRing.Color(red, green, blue));
    }
    myLedRing.show();
    delay(1000);
    displayCount += -1;
    if (displayCount == 0) {
      for (ledIndex = 0; ledIndex <= 11; ledIndex++) {
        myLedRing.setPixelColor(ledIndex, myLedRing.Color(0, 0, 0));
      }
      myLedRing.show();
      delay(10);
    }
  }

}

ESP32 - 12bit RGB LED Ring Clock - Demo

GitHub repository with code, schematics and photos

Credits

#mikrocontroller2019

#mikrocontroller2019

2 projects • 1 follower
Life Is A Beach I'm Just Playing In The Sand ...

Comments