// Libraries
#include <Adafruit_NeoPixel.h>
#include "RTClib.h"
#include <Wire.h>
// Pin Defenition
//Minutes
#define upPinM1 A3
#define leftPinM1 A5
#define rightPinM1 A4
#define upPinM2 A0
#define leftPinM2 A2
#define rightPinM2 A1
// Number of Leds per Strip
#define numLeftStrip 8
#define numRightStrip 8
#define numUptStrip 12
// Clock Settings
RTC_DS1307 rtc;
DateTime myClock;
// Pixels Settings
Adafruit_NeoPixel stripUpM1 = Adafruit_NeoPixel(numUptStrip, upPinM1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripLeftM1 = Adafruit_NeoPixel(numLeftStrip, leftPinM1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripRightM1 = Adafruit_NeoPixel(numRightStrip, rightPinM1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripUpM2 = Adafruit_NeoPixel(numUptStrip, upPinM2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripLeftM2 = Adafruit_NeoPixel(numLeftStrip, leftPinM2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripRightM2 = Adafruit_NeoPixel(numRightStrip, rightPinM2, NEO_GRB + NEO_KHZ800);
void System_Init() {
// Begin all Strips
stripUpM1.begin();
stripLeftM1.begin();
stripRightM1.begin();
stripUpM2.begin();
stripLeftM2.begin();
stripRightM2.begin();
// Set off all LEDS
Show_Leds();
// Clock Init
InitRTC();
// Complete Message
Serial.println("Succesfull at Start!");
}
void Show_Leds() {
//Minutes
stripUpM1.show();
stripLeftM1.show();
stripRightM1.show();
stripUpM2.show();
stripLeftM2.show();
stripRightM2.show();
}
void Turn_Off_Leds(){
for (int i = 0; i <= numUptStrip; i++) {
if (i < 8 ) {
stripRightM1.setPixelColor(i, 0, 0, 0);
stripLeftM1.setPixelColor(i, 0, 0, 0);
stripUpM1.setPixelColor(i, 0, 0, 0);
stripRightM2.setPixelColor(i, 0, 0, 0);
stripLeftM2.setPixelColor(i, 0, 0, 0);
stripUpM2.setPixelColor(i, 0, 0, 0);
}
}
}
void InitRTC() {
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void Display_Digit(int hour, int minutes) {
int hourLeft = hour / 10;
int hourRight = hour % 10;
int minutesLeft = minutes / 10;
int minutesRight = minutes % 10;
Serial.println(minutesLeft);
Serial.println(minutesRight);
//Turn_On_Leds_H1(hourLeft);//Reset all Leds
//Turn_On_Leds_H2(hourRight);//Reset all Leds
Turn_On_Leds_M1(minutesLeft);//Reset all Leds
Turn_On_Leds_M2(minutesRight);//Reset all Leds
}
// Minutes
void Turn_On_Leds_M1(int minutesLeft){
Turn_Off_Leds();
switch (minutesLeft) {
case 0:
for (int i = 0; i <= numUptStrip; i++) {
if (i < 8 ) {
stripRightM1.setPixelColor(i, 255, 0, 0);
stripLeftM1.setPixelColor(i, 255, 0, 0);
}
if (i < 4 )
stripUpM1.setPixelColor(i, 255, 0, 0);
else if ( i >= 8)
stripUpM1.setPixelColor(i, 255, 0, 0);
}
break;
case 1:
for (int i = 0; i < numRightStrip; i++) {
stripRightM1.setPixelColor(i, 255, 0, 0);
}
break;
case 2:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM1.setPixelColor(i, 255, 0, 0);
if ( i < 4) {
stripLeftM1.setPixelColor(i, 255, 0, 0);
}
else {
stripRightM1.setPixelColor(i, 255, 0, 0);
}
}
break;
case 3:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM1.setPixelColor(i, 255, 0, 0);
stripRightM1.setPixelColor(i, 255, 0, 0);
}
break;
case 4:
for (int i = 0; i <= numUptStrip; i++) {
stripRightM1.setPixelColor(i, 255, 0, 0);
if (4 <= i && i < 8 ) {
stripUpM1.setPixelColor(i, 255, 0, 0);
stripLeftM1.setPixelColor(i, 255, 0, 0);
}
}
break;
case 5:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM1.setPixelColor(i, 255, 0, 0);
if ( i > 4) {
stripLeftM1.setPixelColor(i, 255, 0, 0);
}
else {
stripRightM1.setPixelColor(i, 255, 0, 0);
}
}
break;
case 6:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM1.setPixelColor(i, 255, 0, 0);
stripLeftM1.setPixelColor(i, 255, 0, 0);
if ( i < 4) {
stripRightM1.setPixelColor(i, 255, 0, 0);
}
}
break;
case 7:
for (int i = 0; i <= numUptStrip; i++) {
stripRightM1.setPixelColor(i, 255, 0, 0);
if ( i < 4) {
stripUpM1.setPixelColor(i, 255, 0, 0);
}
}
break;
case 8:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM1.setPixelColor(i, 255, 0, 0);
stripRightM1.setPixelColor(i, 255, 0, 0);
stripLeftM1.setPixelColor(i, 255, 0, 0);
}
break;
case 9:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM1.setPixelColor(i, 255, 0, 0);
stripRightM1.setPixelColor(i, 255, 0, 0);
if ( i >= 4) {
stripLeftM1.setPixelColor(i, 255, 0, 0);
}
}
break;
}
Show_Leds();
}
void Turn_On_Leds_M2(int minutesRight){
Turn_Off_Leds();
switch (minutesRight) {
case 0:
for (int i = 0; i <= numUptStrip; i++) {
if (i < 8 ) {
stripRightM2.setPixelColor(i, 255, 0, 0);
stripLeftM2.setPixelColor(i, 255, 0, 0);
}
if (i < 4 )
stripUpM2.setPixelColor(i, 255, 0, 0);
else if ( i >= 8)
stripUpM2.setPixelColor(i, 255, 0, 0);
}
break;
case 1:
for (int i = 0; i < numRightStrip; i++) {
stripRightM2.setPixelColor(i, 255, 0, 0);
}
break;
case 2:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM2.setPixelColor(i, 255, 0, 0);
if ( i < 4) {
stripLeftM2.setPixelColor(i, 255, 0, 0);
}
else {
stripRightM2.setPixelColor(i, 255, 0, 0);
}
}
break;
case 3:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM2.setPixelColor(i, 255, 0, 0);
stripRightM2.setPixelColor(i, 255, 0, 0);
}
break;
case 4:
for (int i = 0; i <= numUptStrip; i++) {
stripRightM2.setPixelColor(i, 255, 0, 0);
if (4 <= i && i < 8 ) {
stripUpM2.setPixelColor(i, 255, 0, 0);
stripLeftM2.setPixelColor(i, 255, 0, 0);
}
}
break;
case 5:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM2.setPixelColor(i, 255, 0, 0);
if ( i > 4) {
stripLeftM2.setPixelColor(i, 255, 0, 0);
}
else {
stripRightM2.setPixelColor(i, 255, 0, 0);
}
}
break;
case 6:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM2.setPixelColor(i, 255, 0, 0);
stripLeftM2.setPixelColor(i, 255, 0, 0);
if ( i < 4) {
stripRightM2.setPixelColor(i, 255, 0, 0);
}
}
break;
case 7:
for (int i = 0; i <= numUptStrip; i++) {
stripRightM2.setPixelColor(i, 255, 0, 0);
if ( i < 4) {
stripUpM2.setPixelColor(i, 255, 0, 0);
}
}
break;
case 8:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM2.setPixelColor(i, 255, 0, 0);
stripRightM2.setPixelColor(i, 255, 0, 0);
stripLeftM2.setPixelColor(i, 255, 0, 0);
}
break;
case 9:
for (int i = 0; i <= numUptStrip; i++) {
stripUpM2.setPixelColor(i, 255, 0, 0);
stripRightM2.setPixelColor(i, 255, 0, 0);
if ( i >= 4) {
stripLeftM2.setPixelColor(i, 255, 0, 0);
}
}
break;
}
Show_Leds();
}
// Global Variables
int hour = 0, minutes = 0;// hourLeft = 0, hourRight = 0;
void setup() {
Serial.begin(9600);
System_Init();
}
void loop() {
myClock = rtc.now();
hour = myClock.hour();
minutes = myClock.minute();
//Print Currennt Time
Serial.print("Time -> ");
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minutes, DEC);
Serial.print(":");
Serial.print(myClock.second(), DEC);
// Set Numbers on Display
Display_Digit(hour, minutes);
}