#include <RTClib.h>
#include <Adafruit_NeoPixel.h>
#define PIN1 3
#define PIN2 5
#define PIN3 6
#define PIN4 9
#define BUTTONPIN 12
#define DOTPIN 10
#define NUMPIXELS 28
#define BRIGHTNESS 240 // 0 - 255
// Define all 4 Modules
Adafruit_NeoPixel module1 = Adafruit_NeoPixel(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel module2 = Adafruit_NeoPixel(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel module3 = Adafruit_NeoPixel(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel module4 = Adafruit_NeoPixel(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);
// Define both dots in the middle
Adafruit_NeoPixel dots = Adafruit_NeoPixel(1, DOTPIN, NEO_GRB + NEO_KHZ800);
int delayval = 0;
RTC_DS1307 rtc;
// RGB colors
#define RED 255
#define GREEN 23
#define BLUE 235
// Splitting numbers variables
int hour_tens;
int hour_ones;
int min_tens;
int min_ones;
// Variable for storing previous number in order to clear LED strip
int previous_min_ones;
int previous_min_tens;
int previous_hour_ones;
int previous_hour_tens;
// TimeChange Button state variables
bool lastButtonState = LOW;
bool currentButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
// Flag for DST (Daylight Saving Time) correction
bool isDST = false; // Set this to true if currently in DST
void setup() {
// Start pixels
module1.begin();
module1.setBrightness(BRIGHTNESS);
module2.begin();
module2.setBrightness(BRIGHTNESS);
module3.begin();
module3.setBrightness(BRIGHTNESS);
module4.begin();
module4.setBrightness(BRIGHTNESS);
dots.begin();
dots.setBrightness(BRIGHTNESS);
dots.setPixelColor(0, dots.Color(RED, GREEN, BLUE));
dots.show();
Serial.begin(9600);
pinMode(BUTTONPIN, INPUT_PULLUP);
// Real Time Clock
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
// Display "----" in RED if RTC isn't found
module1.clear();
module2.clear();
module3.clear();
module4.clear();
for (int i = 24; i < 28; i++) {
module1.setPixelColor(i, module1.Color(255, 0, 0));
module1.show();
module3.setPixelColor(i, module3.Color(255, 0, 0));
module3.show();
module4.setPixelColor(i, module4.Color(255, 0, 0));
module4.show();
delay(delayval);
}
for (int i = 0; i < 4; i++) {
module2.setPixelColor(i, module2.Color(255, 0, 0));
module2.show();
}
while (1) {} // Hold Error "----"
}
if (!rtc.isrunning()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // calibrate RTC
}
}
void loop() {
DateTime displayTime = rtc.now();
Serial.print(displayTime.hour(), DEC);
Serial.print(':');
Serial.print(displayTime.minute(), DEC);
Serial.print(':');
Serial.println(displayTime.second(), DEC);
// Debounce the button
bool reading = digitalRead(BUTTONPIN);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
// Debounce Time
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != currentButtonState) {
currentButtonState = reading;
if (currentButtonState == LOW) {
if (isDST) {
adjustTime(1); // Add one hour when the button is pressed if not in DST
} else {
adjustTime(-1); // Subtract one hour when the button is pressed if in DST
}
}
}
}
lastButtonState = reading;
// Splitting Hours and minutes into digits
hour_tens = displayTime.hour() / 10;
hour_ones = displayTime.hour() % 10;
min_tens = displayTime.minute() / 10;
min_ones = displayTime.minute() % 10;
// Showing LED stripes
strip_module1(hour_tens);
strip_module2(hour_ones);
strip_module3(min_tens);
strip_module4(min_ones);
// Clearing LED Strip if number refreshes
if (min_ones != previous_min_ones) {
module4.clear();
previous_min_ones = min_ones;
}
if (min_tens != previous_min_tens) {
module3.clear();
previous_min_tens = min_tens;
}
if (hour_ones != previous_hour_ones) {
module2.clear();
previous_hour_ones = hour_ones;
}
if (hour_tens != previous_hour_tens) {
module1.clear();
previous_hour_tens = hour_tens;
}
}
// Function for changing Summer to Wintertime or vice versa
void adjustTime(int hours) {
DateTime now = rtc.now();
DateTime newTime = now + TimeSpan(0, hours, 0, 0);
rtc.adjust(newTime);
// Toggle DST flag if the button is pressed
isDST = !isDST;
}
// MODULE 1
void module1_a1() {
for(int i=0;i<4;i++){
module1.setPixelColor(i, module1.Color(RED,GREEN,BLUE));
module1.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module1_a2() {
for(int i=4;i<8;i++){
module1.setPixelColor(i, module1.Color(RED,GREEN,BLUE));
module1.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module1_a3() {
for(int i=8;i<12;i++){
module1.setPixelColor(i, module1.Color(RED,GREEN,BLUE));
module1.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module1_a4() {
for(int i=12;i<16;i++){
module1.setPixelColor(i, module1.Color(RED,GREEN,BLUE));
module1.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module1_a5() {
for(int i=16;i<20;i++){
module1.setPixelColor(i, module1.Color(RED,GREEN,BLUE));
module1.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module1_a6() {
for(int i=20;i<24;i++){
module1.setPixelColor(i, module1.Color(RED,GREEN,BLUE));
module1.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module1_a7() {
for(int i=24;i<28;i++){
module1.setPixelColor(i, module1.Color(RED,GREEN,BLUE));
module1.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void strip_module1(int Num){
switch (Num){
case 0:
module1_a1();
module1_a2();
module1_a3();
module1_a4();
module1_a5();
module1_a6();
break;
case 1:
module1_a1(),
module1_a6();
break;
case 2:
module1_a2();
module1_a3();
module1_a5(),
module1_a6();
module1_a7();
break;
case 3:
module1_a1();
module1_a2();
module1_a5();
module1_a6();
module1_a7();
break;
case 4:
module1_a1();
module1_a4();
module1_a6();
module1_a7();
break;
case 5:
module1_a1();
module1_a2();
module1_a4();
module1_a5();
module1_a7();
break;
case 6:
module1_a1();
module1_a2();
module1_a3();
module1_a4();
module1_a5();
module1_a7();
break;
case 7:
module1_a1();
module1_a5();
module1_a6();
break;
case 8:
module1_a1();
module1_a2();
module1_a3();
module1_a4();
module1_a5();
module1_a6();
module1_a7();
break;
case 9:
module1_a1();
module1_a2();
module1_a4();
module1_a5();
module1_a6();
module1_a7();
break;
}
}
// MODULE 2
void module2_a1() {
for(int i=0;i<4;i++){
module2.setPixelColor(i, module2.Color(RED,GREEN,BLUE));
module2.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module2_a2() {
for(int i=4;i<8;i++){
module2.setPixelColor(i, module2.Color(RED,GREEN,BLUE));
module2.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module2_a3() {
for(int i=8;i<12;i++){
module2.setPixelColor(i, module2.Color(RED,GREEN,BLUE));
module2.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module2_a4() {
for(int i=12;i<16;i++){
module2.setPixelColor(i, module2.Color(RED,GREEN,BLUE));
module2.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module2_a5() {
for(int i=16;i<20;i++){
module2.setPixelColor(i, module2.Color(RED,GREEN,BLUE));
module2.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module2_a6() {
for(int i=20;i<24;i++){
module2.setPixelColor(i, module2.Color(RED,GREEN,BLUE));
module2.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module2_a7() {
for(int i=24;i<28;i++){
module2.setPixelColor(i, module2.Color(RED,GREEN,BLUE));
module2.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void strip_module2(int Num){
switch (Num){
case 0:
module2_a2();
module2_a3();
module2_a4();
module2_a5();
module2_a6();
module2_a7();
break;
case 1:
module2_a2(),
module2_a7();
break;
case 2:
module2_a1();
module2_a2();
module2_a3(),
module2_a5();
module2_a6();
break;
case 3:
module2_a1();
module2_a2();
module2_a3();
module2_a6();
module2_a7();
break;
case 4:
module2_a1();
module2_a2();
module2_a4();
module2_a7();
break;
case 5:
module2_a1();
module2_a3();
module2_a4();
module2_a6();
module2_a7();
break;
case 6:
module2_a1();
module2_a3();
module2_a4();
module2_a5();
module2_a6();
module2_a7();
break;
case 7:
module2_a2();
module2_a3();
module2_a7();
break;
case 8:
module2_a1();
module2_a2();
module2_a3();
module2_a4();
module2_a5();
module2_a6();
module2_a7();
break;
case 9:
module2_a1();
module2_a2();
module2_a3();
module2_a4();
module2_a6();
module2_a7();
break;
}
}
// MODULE 3
void module3_a1() {
for(int i=0;i<4;i++){
module3.setPixelColor(i, module3.Color(RED,GREEN,BLUE));
module3.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module3_a2() {
for(int i=4;i<8;i++){
module3.setPixelColor(i, module3.Color(RED,GREEN,BLUE));
module3.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module3_a3() {
for(int i=8;i<12;i++){
module3.setPixelColor(i, module3.Color(RED,GREEN,BLUE));
module3.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module3_a4() {
for(int i=12;i<16;i++){
module3.setPixelColor(i, module3.Color(RED,GREEN,BLUE));
module3.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module3_a5() {
for(int i=16;i<20;i++){
module3.setPixelColor(i, module3.Color(RED,GREEN,BLUE));
module3.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module3_a6() {
for(int i=20;i<24;i++){
module3.setPixelColor(i, module3.Color(RED,GREEN,BLUE));
module3.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module3_a7() {
for(int i=24;i<28;i++){
module3.setPixelColor(i, module3.Color(RED,GREEN,BLUE));
module3.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void strip_module3(int Num){
switch (Num){
case 0:
module3_a1();
module3_a2();
module3_a3();
module3_a4();
module3_a5();
module3_a6();
break;
case 1:
module3_a3(),
module3_a4();
break;
case 2:
module3_a1();
module3_a2();
module3_a4(),
module3_a5();
module3_a7();
break;
case 3:
module3_a2();
module3_a3();
module3_a4();
module3_a5();
module3_a7();
break;
case 4:
module3_a3();
module3_a4();
module3_a6();
module3_a7();
break;
case 5:
module3_a2();
module3_a3();
module3_a5();
module3_a6();
module3_a7();
break;
case 6:
module3_a1();
module3_a2();
module3_a3();
module3_a5();
module3_a6();
module3_a7();
break;
case 7:
module3_a3();
module3_a4();
module3_a5();
break;
case 8:
module3_a1();
module3_a2();
module3_a3();
module3_a4();
module3_a5();
module3_a6();
module3_a7();
break;
case 9:
module3_a2();
module3_a3();
module3_a4();
module3_a5();
module3_a6();
module3_a7();
break;
}
}
// MODULE 4
void module4_a1() {
for(int i=0;i<4;i++){
module4.setPixelColor(i, module4.Color(RED,GREEN,BLUE));
module4.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module4_a2() {
for(int i=4;i<8;i++){
module4.setPixelColor(i, module4.Color(RED,GREEN,BLUE));
module4.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module4_a3() {
for(int i=8;i<12;i++){
module4.setPixelColor(i, module4.Color(RED,GREEN,BLUE));
module4.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module4_a4() {
for(int i=12;i<16;i++){
module4.setPixelColor(i, module4.Color(RED,GREEN,BLUE));
module4.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module4_a5() {
for(int i=16;i<20;i++){
module4.setPixelColor(i, module4.Color(RED,GREEN,BLUE));
module4.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module4_a6() {
for(int i=20;i<24;i++){
module4.setPixelColor(i, module4.Color(RED,GREEN,BLUE));
module4.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void module4_a7() {
for(int i=24;i<28;i++){
module4.setPixelColor(i, module4.Color(RED,GREEN,BLUE));
module4.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void strip_module4(int Num){
switch (Num){
case 0:
module4_a1();
module4_a2();
module4_a3();
module4_a4();
module4_a5();
module4_a6();
break;
case 1:
module4_a3(),
module4_a4();
break;
case 2:
module4_a1();
module4_a2();
module4_a4(),
module4_a5();
module4_a7();
break;
case 3:
module4_a2();
module4_a3();
module4_a4();
module4_a5();
module4_a7();
break;
case 4:
module4_a3();
module4_a4();
module4_a6();
module4_a7();
break;
case 5:
module4_a2();
module4_a3();
module4_a5();
module4_a6();
module4_a7();
break;
case 6:
module4_a1();
module4_a2();
module4_a3();
module4_a5();
module4_a6();
module4_a7();
break;
case 7:
module4_a3();
module4_a4();
module4_a5();
break;
case 8:
module4_a1();
module4_a2();
module4_a3();
module4_a4();
module4_a5();
module4_a6();
module4_a7();
break;
case 9:
module4_a2();
module4_a3();
module4_a4();
module4_a5();
module4_a6();
module4_a7();
break;
}
}