#include <Wire.h>
#include <DS3231.h>
#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 64
#define BRIGHTNESS 80
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
DS3231 clock;
RTCDateTime dt;
int minutes;
int hours;
int CurrentTime[4];
int PreviousTime[4];
int ColorMinutes;
int ColorPastTo;
int ColorHour;
int Time_Comp[19][7]{ {62,59,56,99,99,99,99},
{48,49,62,99,99,99,99},
{44,43,42,41,40,99,99},
{63,62,61,60,99,99,99},
{32,33,34,35,99,99,99},
{47,46,45,99,99,99,99},
{47,52,53,54,55,99,99},
{35,36,37,38,39,99,99},
{59,58,57,56,99,99,99},
{39,40,55,99,99,99,99},
{50,51,52,53,54,55,99},
{48,49,50,51,53,54,99},
{30,29,28,27,99,99,99},
{27,26,99,99,99,99,99},
{16,17,18,19,99,99,99},
{ 1, 3, 4,99,99,99,99},
{15,14,13,12,11,10, 9},
{ 1, 2, 3, 4, 5, 6,99},
{20,21,22,23,99,99,99}};
CRGB Colors[11]{CRGB::Chartreuse,CRGB::Orange,CRGB::BlueViolet,CRGB::Red,CRGB::Cyan,CRGB::Pink,
CRGB::Green,CRGB::Purple,CRGB::Yellow,CRGB::White,CRGB::Blue};
void LitAll(){
for(int i=0;i<=80;i++){
LEDS.setBrightness(i);
FastLED.show();
delay(120-i);
}
}
void DimAll(){
for(int i=80;i>=0;i--){
LEDS.setBrightness(i);
FastLED.show();
delay(60);
}
}
void setup() {
Serial.begin(9600);
clock.begin();
//clock.setDateTime(__DATE__, __TIME__);
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
}
void loop(){
PreviousTime[0]=CurrentTime[0];
PreviousTime[1]=CurrentTime[1];
PreviousTime[2]=CurrentTime[2];
PreviousTime[3]=CurrentTime[3];
dt = clock.getDateTime();
minutes=int((dt.minute)/5)*5;
if (minutes<35 and minutes>=0) hours=dt.hour ;else hours=dt.hour+1 ;
if (minutes==0) {CurrentTime[0]=99;CurrentTime[1]=99;}
if ((minutes==5) or (minutes==55)) {CurrentTime[0]=14;CurrentTime[1]=99;}
if ((minutes==10) or (minutes==50)) {CurrentTime[0]=15;CurrentTime[1]=99;}
if ((minutes==15) or (minutes==45)) {CurrentTime[0]=16;CurrentTime[1]=99;}
if ((minutes==20) or (minutes==40)) {CurrentTime[0]=17;CurrentTime[1]=99;}
if ((minutes==25) or (minutes==35)) {CurrentTime[0]=17;CurrentTime[1]=14;}
if (minutes==30) {CurrentTime[0]=18;CurrentTime[1]=99;}
if (minutes>= 5 and minutes<35) CurrentTime[2]=12;
if (minutes>=35 and minutes<=59) CurrentTime[2]=13;
if (minutes==0) CurrentTime[2]=99;
CurrentTime[3]=hours - int(hours/12)*12-1;
if (CurrentTime[3]<0) CurrentTime[3]=CurrentTime[3]+12;
if (PreviousTime[0]!=CurrentTime[0]or PreviousTime[1]!=CurrentTime[1]) {
DimAll();
delay(2000);
if (PreviousTime[0]!=99) for (int j=0;j<7;j++) leds[Time_Comp[PreviousTime[0]][j]]=CHSV( 0 , 0, 0);
if (PreviousTime[1]!=99) for (int j=0;j<7;j++) leds[Time_Comp[PreviousTime[1]][j]]=CHSV( 0 , 0, 0);
if (PreviousTime[2]!=99) for (int j=0;j<7;j++) leds[Time_Comp[PreviousTime[2]][j]]=CHSV( 0 , 0, 0);
if (PreviousTime[3]!=99) for (int j=0;j<7;j++) leds[Time_Comp[PreviousTime[3]][j]]=CHSV( 0 , 0, 0);
ColorMinutes=random(0,10);
if (CurrentTime[0]!=99) for (int j=0;j<7;j++) leds[Time_Comp[CurrentTime[0]][j]]=Colors[ColorMinutes];
if (CurrentTime[1]!=99) for (int j=0;j<7;j++) leds[Time_Comp[CurrentTime[1]][j]]=Colors[ColorMinutes];
ColorPastTo=random(0,10);
while (ColorPastTo==ColorMinutes){
ColorPastTo=random(0,10);
}
if (CurrentTime[2]!=99) for (int j=0;j<7;j++) leds[Time_Comp[CurrentTime[2]][j]]=Colors[ColorPastTo];
ColorHour=random(0,10);
while ( ColorHour==ColorPastTo or ColorHour==ColorMinutes ){
ColorHour=random(0,10);
}
for (int j=0;j<7;j++) leds[Time_Comp[CurrentTime[3]][j]]=Colors[ColorHour];
//FastLED.show();
LitAll();
}
}
Comments