#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 RTC;
int HOUR, MINUT, SECOND;
int latchPin = 4; //pin 12 on the 595 o3 3
int dataPin = 2; //pin 14 on the 595 or 4
int clockPin = 3; //pin 11 on the 595 or 2
int shift = 256;
int units, tens, hundreds, thousands,tenthousand,lakh;
int times = 1;
const int alarmHour = 17;
const int alarmMinute = 26;
void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(13, OUTPUT);
Wire.begin();
RTC.begin();
if (!RTC.isrunning())
{
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop() {
DateTime now = RTC.now();
HOUR = now.hour();
MINUT = now.minute();
SECOND = now.second();
//Serial.println(MINUT);
if (HOUR < 10)
{
tenthousand = HOUR;
lakh = HOUR/10;
}
else if (HOUR >= 10 && HOUR < 24)
{
tenthousand = HOUR % 10;
lakh = HOUR / 10;
}
if (MINUT <= 9)
{
hundreds = MINUT;
thousands = MINUT/10;
}
else if (MINUT > 9 && MINUT <= 60)
{
hundreds = MINUT % 10;
thousands = MINUT / 10;
}
if (SECOND <= 9)
{
units = SECOND;
tens = SECOND/10;
}
else if (SECOND > 9 && SECOND <= 60)
{
units = SECOND % 10;
tens = SECOND / 10;
}
switch (hundreds)
{
case 0:
//0
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B01000000 );
digitalWrite(latchPin, HIGH);
break;
case 1:
//1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B01111001);
digitalWrite(latchPin, HIGH);
break;
case 2:
//2
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100100);
digitalWrite(latchPin, HIGH);
break;
case 3:
//3
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00110000);
digitalWrite(latchPin, HIGH);
break;
case 4:
//4
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00011001);
digitalWrite(latchPin, HIGH);
break;
case 5:
//5
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010010);
digitalWrite(latchPin, HIGH);
break;
case 6:
//6
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00000010);
digitalWrite(latchPin, HIGH);
break;
case 7:
//7
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B01111000);
digitalWrite(latchPin, HIGH);
break;
case 8:
//8
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00000000);
digitalWrite(latchPin, HIGH);
break;
case 9:
//9
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000);
digitalWrite(latchPin, HIGH);
break;
}
delay(times);
switch (thousands)
{
case 0:
//0
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 192 );
digitalWrite(latchPin, HIGH);
break;
case 1:
//1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 249);
digitalWrite(latchPin, HIGH);
break;
case 2:
//2
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 164);
digitalWrite(latchPin, HIGH);
break;
case 3:
//3
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 176);
digitalWrite(latchPin, HIGH);
break;
case 4:
//4
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 153);
digitalWrite(latchPin, HIGH);
break;
case 5:
//5
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 146);
digitalWrite(latchPin, HIGH);
break;
}
delay(times);
switch (tenthousand)
{
case 0:
//0
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 );
digitalWrite(latchPin, HIGH);
break;
case 1:
//1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 121);
digitalWrite(latchPin, HIGH);
break;
case 2:
//2
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 36);
digitalWrite(latchPin, HIGH);
break;
case 3:
//3
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 48);
digitalWrite(latchPin, HIGH);
break;
case 4:
//4
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 25);
digitalWrite(latchPin, HIGH);
break;
case 5:
//5
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 18);
digitalWrite(latchPin, HIGH);
break;
case 6:
//6
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 2);
digitalWrite(latchPin, HIGH);
break;
case 7:
//7
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 120);
digitalWrite(latchPin, HIGH);
break;
case 8:
//8
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 0);
digitalWrite(latchPin, HIGH);
break;
case 9:
//9
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 16);
digitalWrite(latchPin, HIGH);
break;
}
delay(times);
switch (lakh)
{
case 0:
//0
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 192 );
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 1:
//1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 249);
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 2:
//2
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 164);
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 3:
//3
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 176);
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 4:
//4
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 153);
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 5:
//5
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 146);
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 6:
//6
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 130);
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 7:
//7
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 248);
digitalWrite(latchPin, HIGH);
//delay(500);
break;
case 8:
//8
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 128);
digitalWrite(latchPin, HIGH);
break;
case 9:
//9
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 152);
digitalWrite(latchPin, HIGH);
break;
}
delay(times);
//alarm section
switch (units)
{
case 0:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B11000000);
digitalWrite(latchPin, HIGH);
break;
}
case 1:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B11111001);
digitalWrite(latchPin, HIGH);
break;
}
case 2:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10100100);
digitalWrite(latchPin, HIGH);
break;
}
case 3:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10110000);
digitalWrite(latchPin, HIGH);
break;
}
case 4:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST,0B10011001 );
digitalWrite(latchPin, HIGH);
break;
}
case 5:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10010010);
digitalWrite(latchPin, HIGH);
break;
}
case 6:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00000010);
digitalWrite(latchPin, HIGH);
break;
}
case 7:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B11111000);
digitalWrite(latchPin, HIGH);
break;
}
case 8:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10000000);
digitalWrite(latchPin, HIGH);
break;
}
case 9:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00100000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000);
digitalWrite(latchPin, HIGH);
break;
}
}
delay(times);
switch (tens)
{
case 0:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B11000000);
digitalWrite(latchPin, HIGH);
break;
}
case 1:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B11111001);
digitalWrite(latchPin, HIGH);
break;
}
case 2:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10100100);
digitalWrite(latchPin, HIGH);
break;
}
case 3:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10110000);
digitalWrite(latchPin, HIGH);
break;
}
case 4:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000);
shiftOut(dataPin, clockPin, MSBFIRST,0B10011001 );
digitalWrite(latchPin, HIGH);
break;
}
case 5:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10010010);
digitalWrite(latchPin, HIGH);
break;
}
case 6:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00000010);
digitalWrite(latchPin, HIGH);
break;
}
case 7:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B11111000);
digitalWrite(latchPin, HIGH);
break;
}
case 8:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B10000000);
digitalWrite(latchPin, HIGH);
break;
}
case 9:
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000 );
shiftOut(dataPin, clockPin, MSBFIRST, 0B00010000);
digitalWrite(latchPin, HIGH);
break;
}
}
if (HOUR == alarmHour && MINUT == alarmMinute)
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
}
Comments