Yes, night can be turned on at any time between certain hours, it just controls the color of the lights.
I talk about the switch more here.
here's the whole updated code:
#include <DS3231.h> //Include the clock library RTC_DS3231 rtc
#include <FastLED.h>
// Changable Vars
CRGB leds[84];
CRGB leds2[84];
const int switchPin = 3;
const int switchPin2 = 5;
int fadeTime = 30; // How long the light will fade to max
int i = 0;
int z = 21;
int x = 41;
int setHour = 8; // wake (military time)
int setMin = 30;
int bedHour = 23; // bed
int bedMin = 0;
int workHour = 10; // work
int workMin = 0;
int restHour = 18; // rest
int restMin = 0;
int endHour = 23;
int endMin = 59;
int nightHour = 0; // nightlight
int nightMin = 0;
// Set up Vars
DS3231 rtc(SDA, SCL);
Time t;
void start();
void setup()
{
FastLED.addLeds<WS2812, 10, GRB>(leds, 84);
FastLED.addLeds<SK6812, 9, GRB>(leds2, 84);
pinMode(3, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
Serial.begin(9600); // Match to serial monitor
rtc.begin();
}
void loop()
{
Serial.print("pin3: ");
Serial.println(digitalRead(3));
Serial.print("pin5: ");
Serial.println(digitalRead(5));
t = rtc.getTime(); // Make a time class called 't'
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
if (digitalRead(3) == HIGH && digitalRead(5) == LOW){
setting1();
}else if (digitalRead(5) == HIGH && digitalRead(3) == LOW){
setting2();
}else {
setting3();
}
}
void sunrise()
{
unsigned long tempTime = millis();
// segment 1
for(int i = 0; i <= 20; i++)
{
leds[i] = CRGB(50, 0, 0);
leds2[i] = CRGB(100, 0, 0);
}
FastLED.show();
// segments 2 & 4
// 1
tempTime = millis();
while(millis() - tempTime < (225000)){
if (digitalRead(3) == LOW && digitalRead(5) == HIGH){
setting2();
} else if (digitalRead(3) == LOW && digitalRead(5) == LOW){
setting3();
}
}
for(int i = 83; i >= 63; i -= 3)
{
leds[i] = CRGB(50, 5, 0);
leds2[i] = CRGB(10, 0, 200);
leds[i - 1] = CRGB(50, 5, 0);
leds2[i - 1] = CRGB(10, 0, 200);
leds[i - 2] = CRGB(50, 5, 0);
leds2[i - 2] = CRGB(10, 0, 200);
leds[z] = CRGB(50, 5, 0);
leds2[z] = CRGB(10, 0, 200);
leds[z + 1] = CRGB(50, 5, 0);
leds2[z + 1] = CRGB(10, 0, 200);
leds[z + 2] = CRGB(50, 5, 0);
leds2[z + 2] = CRGB(10, 0, 200);
FastLED.show();
z += 3;
tempTime = millis();
while(millis() - tempTime < (225000)){
if (digitalRead(3) == LOW && digitalRead(5) == HIGH){
setting2();
} else if (digitalRead(3) == LOW && digitalRead(5) == LOW){
setting3();
}
}
}
// segment 3
for(int i = 42; i <= 62; i++)
{
leds[i] = CRGB(50, 5, 5);
leds2[i] = CRGB(10, 0, 200);
}
FastLED.show();
tempTime = millis();
while(millis() - tempTime < (900000)){
if (digitalRead(3) == LOW && digitalRead(5) == HIGH){
setting2();
} else if (digitalRead(3) == LOW && digitalRead(5) == LOW){
setting3();
}
}
for(int i = 0; i <= 83; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(0, 0, 0);
}
delay (1000);
}
void sunset()
{
unsigned long tempTime = millis();
// beginning
for(int i = 0; i <= 20; i++)
{
leds[i] = CRGB(100, 20, 0);
leds2[i] = CRGB(200, 0, 0);
FastLED.show();
}
for(int i = 21; i <= 41; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(255, 0, 100);
FastLED.show();
}
for(int i = 42; i <= 62; i++)
{
leds[i] = CRGB(5, 0, 100);
leds2[i] = CRGB(0, 0, 0);
FastLED.show();
}
for(int i = 63; i <= 83; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(255, 0, 100);
FastLED.show();
}
tempTime = millis();
while(millis() - tempTime < (1800000)){
if (digitalRead(3) == LOW && digitalRead(5) == HIGH){
setting2();
} else if (digitalRead(3) == LOW && digitalRead(5) == LOW){
setting3();
}
}
// segment 1
for(int i = 42; i <= 62; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(0, 0, 0);
FastLED.show();
}
delay((fadeTime * 60000)/8);
tempTime = millis();
while(millis() - tempTime < (225000)){
if (digitalRead(3) == LOW && digitalRead(5) == HIGH){
setting2();
} else if (digitalRead(3) == LOW && digitalRead(5) == LOW){
setting3();
}
}
// segments 2 & 4
for(int i = 63; i <= 83; i += 3)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(0, 0, 0);
leds[i + 1] = CRGB(0, 0, 0);
leds2[i + 1] = CRGB(0, 0, 0);
leds[i + 2] = CRGB(0, 0, 0);
leds2[i + 2] = CRGB(0, 0, 0);
leds[x] = CRGB(0, 0, 0);
leds2[x] = CRGB(0, 0, 0);
leds[x - 1] = CRGB(0, 0, 0);
leds2[x - 1] = CRGB(0, 0, 0);
leds[x - 2] = CRGB(0, 0, 0);
leds2[x - 2] = CRGB(0, 0, 0);
FastLED.show();
x -= 3;
tempTime = millis();
while(millis() - tempTime < (225000)){
if (digitalRead(3) == LOW && digitalRead(5) == HIGH){
setting2();
} else if (digitalRead(3) == LOW && digitalRead(5) == LOW){
setting3();
}
}
}
// segment 3
for(int i = 0; i <= 20; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(0, 0, 0);
FastLED.show();
}
}
void work()
{
for(int i = 0; i <= 20; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(0, 50, 200);
FastLED.show();
}
for(int i = 21; i <= 83; i++)
{
leds[i] = CRGB(0, 50, 200);
leds2[i] = CRGB(0, 200, 0);
FastLED.show();
}
delay (1000);
}
void rest()
{
for(int i = 0; i <= 20; i++)
{
leds[i] = CRGB(100, 20, 0);
leds2[i] = CRGB(255, 0, 100);
FastLED.show();
}
for(int i = 21; i <= 41; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(255, 0, 100);
FastLED.show();
}
for(int i = 42; i <= 62; i++)
{
leds[i] = CRGB(5, 0, 200);
leds2[i] = CRGB(0, 0, 0);
FastLED.show();
}
for(int i = 63; i <= 83; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(255, 0, 100);
FastLED.show();
}
delay (1000);
}
void night()
{
for(int i = 0; i <= 20; i++)
{
leds[i] = CRGB(100, 0, 0);
leds2[i] = CRGB(0, 0, 0);
FastLED.show();
}
for(int i = 21; i <= 83; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(0, 0, 0);
FastLED.show();
}
delay (1000);
}
void setting1(){
if (t.hour >= setHour && t.hour < workHour && t.min >= setMin) // Check if it's time to wake up!
{
sunrise();
}
else if (t.hour >= bedHour && t.min >= bedMin)
{
sunset();
}
}
void setting2(){
if (t.hour >= workHour && t.hour < restHour && t.min >= workMin)
{
work();
}
else if (t.hour >= restHour && t.hour <= endHour && t.min >= restMin && t.min <= endMin)
{
rest();
}
else if (t.hour >= nightHour && t.hour < workHour && t.min >= nightMin)
{
night();
}
}
void setting3(){
for(int i = 0; i <= 83; i++)
{
leds[i] = CRGB(0, 0, 0);
leds2[i] = CRGB(0, 0, 0);
FastLED.show();
}
// Wait one second before repeating
delay (1000);
}