Untitled
1 year ago in Plain Text
#include "RTClib.h"
RTC_DS3231 rtc;
#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif
#define PIN 13
unsigned long previousMillis = 0;
const unsigned long interval = 60000;
int r;
int g;
int b;
int i;
bool flag = 0;
#define NUMPIXELS 8
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
#if defined(AVR_ATtiny85) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
pixels.begin();
Serial.begin(57600);
#ifndef ESP8266
while (!Serial);
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(DATE), F(TIME)));
}
rtc.adjust(DateTime(F(DATE), F(TIME)));
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
if(now.hour() == 2 and flag != 1)
{
flag = 1;
}
if(now.hour() >= 4 and flag == 1)
{
flag = 0;
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if(now.hour() == 2 and flag != 1)
{
flag = 1;
}
if(now.hour() >= 4 and flag == 1)
{
flag = 0;
}
if(now.hour() >= 20 and flag != 1)
{
r = 1;
g = 1;
b = 1;
}
if(now.hour() >= 20 or now.hour() <= 2 and flag != 1)
{
r = 0;
g = 0;
b = 0;
}else if( now.hour() <= 9 and now.hour() >= 2)
{
if(now.minute() % 3 == 0)
{
r += 2;
g++;
b = 50;
}
}else if( now.hour() <= 12 and now.hour() >= 9)
{
if (r != b){ r -= 2;}
if (g != b){ g--;}
if(now.minute() % 2 == 0)
{
b = 50;
}
}else if( now.hour() <= 19 and now.hour() >= 12)
{
r=g=b=50;
}else if( now.hour() <= 20 and now.hour() >= 19)
{
if (b >= r){ b -= 2;}
if(now.minute() % 1 == 0)
{
r += 2;
g++;
}
}
}
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(r, g, b));
pixels.show();
delay(1);
}
}