So I made a clock but now for some reason it has time dilation.
It started 16:30 4/1/2018 but at 07:30 it was at around 7:07. I belive this has to do with CPU speed but I'm new to this. Help?!
Code
#include <LiquidCrystal.h>
LiquidCrystal lcd(6, 7, 13, 12, 11, 10);
/* Todays date*/
int seconds = 50;
int minutes = 34;
int hours = 7;
int day = 2;
int month = 4;
int year = 2018;
/*Maximum date*/
int mseconds = 60;
int mminutes = 60;
int mhours = 24;
int mday = 30;
int mmonth = 13;
/*Alarm settings*/
int aseconds = 0;
int aminutes = 35;
int ahours = 7;
int aday = 2;
int aday2 = 3;
int aday3 = 4;
int aday4 = 5;
int aday5 = 6;
int aday6 = 9;
int aday7 = 10;
int aday8 = 11;
int aday9 = 12;
int aday10 = 13;
int aday11 = 16;
int aday12 = 17;
int aday13 = 18;
int aday14 = 19;
int aday15 = 20;
int aday16 = 23;
int aday17 = 24;
int aday18 = 25;
int aday19 = 26;
int aday20 = 27;
int aday21 = 28;
int amonth = 4;
int ayear = 2018;
int sound = 3000;
void setup() {
lcd.begin(16, 2);
}
void loop() {
delay(1000);
if (month == 1)
{
mday = 32;
}
if (month == 2)
{
mday = 29;
}
if (month == 3)
{
mday = 32;
}
if (month == 4)
{
mday = 31;
}
if (month == 5)
{
mday = 32;
}
if (month == 6)
{
mday = 31;
}
if (month == 7)
{
mday = 32;
}
if (month == 8)
{
mday = 32;
}
if (month == 9)
{
mday = 31;
}
if (month == 10)
{
mday = 32;
}
if (month == 11)
{
mday = 31;
}
if (month == 12)
{
mday = 32;
}
seconds = seconds + 1;
if (seconds == mseconds)
{
seconds = 0;
minutes = minutes + 1;
if (minutes == mminutes)
{
minutes = 0;
hours = hours + 1;
if (hours == mhours)
{
hours = 0;
day = day + 1;
if (day == mday)
{
day = 1;
month = month + 1;
if (month == mmonth)
{
month = 1;
year = year + 1;
}
}
}
}
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print(month);
lcd.print("/");
lcd.print(day);
lcd.print("/");
lcd.print(year);
lcd.setCursor(0,2);
lcd.print(hours);
lcd.print(":");
lcd.print(minutes);
lcd.print(":");
lcd.print(seconds);
alarm();
}
int alarm()
{
if (seconds == aseconds)
{
if (minutes == aminutes)
{
if (hours == ahours)
{
if ((day == aday)||(day == aday2)||(day == aday3)||(day == aday4)||(day == aday5)||(day == aday6)||(day == aday7)||(day == aday8)||(day == aday9)||(day == aday10)||(day == aday11)||(day == aday12)||(day == aday13)||(day == aday14)||(day == aday15)||(day == aday16)||(day == aday17)||(day == aday18)||(day == aday19)||(day == aday20)||(day == aday21))
{
if (month == amonth)
{
if (year == ayear)
{
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
tone(5, sound);
delay(250);
noTone(5);
tone(5, sound);
delay(250);
noTone(5);
delay(1000);
seconds = seconds + 15;
}
}
}
}
}
}
}
Code updated