//
// https://www.youtube.com/c/LeventeDaradici/videos
//
#include <MyRealTimeClock.h>
MyRealTimeClock myRTC(6, 7, 8);
#include <EEPROM.h>
#include <Shifty.h>
Shifty shift;
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int test, PrimaCitireA3, IntarziereANIMATIE, InitialZISAPTAMANA, InitialZIUA, InitialLUNA, InitialAN, InitialMINUT, InitialORA, NewMINUT, NewORA, PrimaCitire, UltimaStareButonPlus, UltimaStareButonSetup, StareButonPlus, StareButonSetup, scene, t1, t2 ,o, m, o1, o2, m1, m2, Pminut, Pora, minut, ora, num, zeci, sute, mii = 0;
String STRora,STRmin, STRtemp = "";
String STRt1, STRt2, STRo1, STRo2, STRm1, STRm2 = "";
float temperatura = 0;
unsigned long TimpORA = 10000;
unsigned long TimpTEMP = 20000;
unsigned long currentMillis;
unsigned long startMillis;
bool AfisatTEMP, AfisatORA = false ;
void setup()
{
IntarziereANIMATIE = EEPROM.read(0);
if (IntarziereANIMATIE > 15) IntarziereANIMATIE = 0;
shift.setBitCount(32);
shift.setPins(11, 12, 9);
for (test = 0; test <= 32 ; test++)
{
shift.writeBit(test - 1, LOW);
shift.writeBit(test, HIGH);
delay(500);
}
// myRTC.setDS1302Time(00,18, 30, 1 , 10, 05, 2022);
pinMode(4, INPUT);
pinMode(5, INPUT);
scene = 0;
startMillis = millis();
NewMINUT = myRTC.minutes;
NewORA = myRTC.hours;
}
void loop()
{
if (scene == 0)
{
currentMillis = millis();
if (currentMillis - startMillis <= TimpORA)
{
if (AfisatORA == false)
{
AfiseazaORA();
AfisatORA = true;
AfisatTEMP = false;
}
}
if (currentMillis - startMillis > TimpORA && currentMillis - startMillis <= TimpTEMP)
{
if (AfisatTEMP == false)
{
AfiseazaTEMP();
AfisatORA = false;
AfisatTEMP = true;
}
}
if (currentMillis - startMillis > TimpTEMP)
{
startMillis = millis();
}
}
StareButonSetup = digitalRead(5);
if (StareButonSetup != UltimaStareButonSetup)
{
if (StareButonSetup == HIGH)
{
scene = scene + 1;
if (scene > 3)
{
scene = 0;
InitialAN = myRTC.year;
InitialLUNA = myRTC.month;
InitialZIUA = myRTC.dayofmonth;
InitialZISAPTAMANA = myRTC.dayofweek;
EEPROM.update(0, IntarziereANIMATIE);
startMillis = millis();
myRTC.setDS1302Time(00,NewMINUT, NewORA, InitialZISAPTAMANA , InitialZIUA, InitialLUNA, InitialAN);
AfiseazaORA();
}
if (scene == 1)
{
AfiseazaORA();
StergeCaracterul(4);
StergeCaracterul(3);
PrimaCitire = 0;
}
if (scene == 2)
{
AfiseazaORA();
StergeCaracterul(2);
StergeCaracterul(1);
PrimaCitire = 0;
}
if (scene == 3)
{
StergeRapid();
if (IntarziereANIMATIE == 0) zero(2);
if (IntarziereANIMATIE == 1) unu(2);
if (IntarziereANIMATIE == 2) doi(2);
if (IntarziereANIMATIE == 3) trei(2);
if (IntarziereANIMATIE == 4) patru(2);
if (IntarziereANIMATIE == 5) cinci(2);
if (IntarziereANIMATIE == 6) sase(2);
if (IntarziereANIMATIE == 7) sapte(2);
if (IntarziereANIMATIE == 8) opt(2);
if (IntarziereANIMATIE == 9) noua(2);
if (IntarziereANIMATIE == 10) { unu(1); zero(2);}
if (IntarziereANIMATIE == 11) { unu(1); unu(2);}
if (IntarziereANIMATIE == 12) { unu(1); doi(2);}
if (IntarziereANIMATIE == 13) { unu(1); trei(2);}
if (IntarziereANIMATIE == 14) { unu(1); patru(2);}
if (IntarziereANIMATIE == 15) { unu(1); cinci(2);}
}
}
} else { }
delay(5);
UltimaStareButonSetup = StareButonSetup;
StareButonPlus = digitalRead(4);
if (StareButonPlus != UltimaStareButonPlus)
{
if (StareButonPlus == HIGH)
{
if (scene == 1)
{
if (PrimaCitire == 0)
{
NewORA = myRTC.hours;
InitialORA = NewORA;
PrimaCitire = 1;
}
NewORA = NewORA + 1;
if (NewORA > 23)
{
NewORA = 0;
}
AfiseazaDoarOra(NewORA);
}
if (scene == 2)
{
if (PrimaCitire == 0)
{
NewMINUT = myRTC.minutes;
InitialMINUT = NewMINUT;
PrimaCitire = 1;
}
NewMINUT = NewMINUT + 1;
if (NewMINUT > 59)
{
NewMINUT = 0;
}
AfiseazaDoarMINUTUL(NewMINUT);
}
if (scene == 3)
{
if (PrimaCitireA3 < 1)
{
PrimaCitireA3 = 1;
}
IntarziereANIMATIE = IntarziereANIMATIE + 1;
if (NewORA == 0)
{
if (NewMINUT ==0)
{
NewMINUT = myRTC.minutes;
InitialMINUT = NewMINUT;
NewORA = myRTC.hours;
InitialORA = NewORA;
}
}
if (IntarziereANIMATIE > 15)
{
IntarziereANIMATIE = 0;
}
StergeRapid();
if (IntarziereANIMATIE == 0) zero(2);
if (IntarziereANIMATIE == 1) unu(2);
if (IntarziereANIMATIE == 2) doi(2);
if (IntarziereANIMATIE == 3) trei(2);
if (IntarziereANIMATIE == 4) patru(2);
if (IntarziereANIMATIE == 5) cinci(2);
if (IntarziereANIMATIE == 6) sase(2);
if (IntarziereANIMATIE == 7) sapte(2);
if (IntarziereANIMATIE == 8) opt(2);
if (IntarziereANIMATIE == 9) noua(2);
if (IntarziereANIMATIE == 10) { unu(1); zero(2);}
if (IntarziereANIMATIE == 11) { unu(1); unu(2);}
if (IntarziereANIMATIE == 12) { unu(1); doi(2);}
if (IntarziereANIMATIE == 13) { unu(1); trei(2);}
if (IntarziereANIMATIE == 14) { unu(1); patru(2);}
if (IntarziereANIMATIE == 15) { unu(1); cinci(2);}
}
}
} else { }
delay(5);
UltimaStareButonPlus = StareButonPlus;
}
void AfiseazaDoarMINUTUL(int aMINUT)
{
String STRaMINUT = String(aMINUT);
m1 = STRaMINUT.toInt();
int lungimeMIN = STRaMINUT.length();
if (lungimeMIN < 2)
{
STRm1 = "0";
STRm2 = STRaMINUT.substring(0,1);
}
if (lungimeMIN > 1)
{
STRm1 = STRaMINUT.substring(0,1);
STRm2 = STRaMINUT.substring(1,2);
}
m1 = STRm1.toInt();
m2 = STRm2.toInt();
StergeCaracterul(3);
if (m1 == 0) zero(3);
if (m1 == 1) unu(3);
if (m1 == 2) doi(3);
if (m1 == 3) trei(3);
if (m1 == 4) patru(3);
if (m1 == 5) cinci(3);
if (m1 == 6) sase(3);
if (m1 == 7) sapte(3);
if (m1 == 8) opt(3);
if (m1 == 9) noua(3);
StergeCaracterul(4);
if (m2 == 0) zero(4);
if (m2 == 1) unu(4);
if (m2 == 2) doi(4);
if (m2 == 3) trei(4);
if (m2 == 4) patru(4);
if (m2 == 5) cinci(4);
if (m2 == 6) sase(4);
if (m2 == 7) sapte(4);
if (m2 == 8) opt(4);
if (m2 == 9) noua(4);
}
void AfiseazaDoarOra(int Aora)
{
String STRaORA = String(Aora);
o1 = STRaORA.toInt();
int lungimeORA = STRaORA.length();
if (lungimeORA < 2)
{
STRo1 = "0";
STRo2 = STRaORA.substring(0,1);
}
if (lungimeORA > 1)
{
STRo1 = STRaORA.substring(0,1);
STRo2 = STRaORA.substring(1,2);
}
o1 = STRo1.toInt();
o2 = STRo2.toInt();
StergeCaracterul(1);
if (o1 == 0) zero(1);
if (o1 == 1) unu(1);
if (o1 == 2) doi(1);
StergeCaracterul(2);
if (o2 == 0) zero(2);
if (o2 == 1) unu(2);
if (o2 == 2) doi(2);
if (o2 == 3) trei(2);
if (o2 == 4) patru(2);
if (o2 == 5) cinci(2);
if (o2 == 6) sase(2);
if (o2 == 7) sapte(2);
if (o2 == 8) opt(2);
if (o2 == 9) noua(2);
}
void AfiseazaORA()
{
STRora = "";
STRmin = "";
myRTC.updateTime();
minut = myRTC.minutes;
ora = myRTC.hours;
AfiseazaDoarOra(ora);
AfiseazaDoarMINUTUL(minut);
}
void AfiseazaTEMP()
{
sensors.requestTemperatures();
temperatura = sensors.getTempCByIndex(0);
STRtemp = String(temperatura,0);
int lungimeTEMP = STRtemp.length();
if (lungimeTEMP > 1)
{
STRt1 = STRtemp.substring(0,1);
STRt2 = STRtemp.substring(1,2);
} else
{
STRt1 = "0";
STRt2 = STRtemp.substring(0,1);
}
t1 = STRt1.toInt();
t2 = STRt2.toInt();
StergeCaracterul(1);
if (t1 == 0) zero(1);
if (t1 == 1) unu(1);
if (t1 == 2) doi(1);
if (t1 == 3) trei(1);
if (t1 == 4) patru(1);
if (t1 == 5) cinci(1);
if (t1 == 6) sase(1);
if (t1 == 7) sapte(1);
if (t1 == 8) opt(1);
if (t2 == 9) noua(1);
StergeCaracterul(2);
if (t2 == 0) zero(2);
if (t2 == 1) unu(2);
if (t2 == 2) doi(2);
if (t2 == 3) trei(2);
if (t2 == 4) patru(2);
if (t2 == 5) cinci(2);
if (t2 == 6) sase(2);
if (t2 == 7) sapte(2);
if (t2 == 8) opt(2);
if (t2 == 9) noua(2);
StergeCaracterul(3);
grade();
StergeCaracterul(4);
Celsius();
}
void grade()
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(14, HIGH);
pauza();
shift.writeBit(15, HIGH);
}
void Celsius()
{
shift.writeBit(4, HIGH);
pauza;
shift.writeBit(5, HIGH);
pauza;
shift.writeBit(6, HIGH);
pauza;
shift.writeBit(1, HIGH);
pauza;
}
void StergeRapid()
{
int i;
for (i = 0; i <= 32 ; i++)
{
shift.writeBit(32-i, LOW);
}
}
void StergeTotul()
{
int i;
for (i = 0; i <= 32 ; i++)
{
shift.writeBit(32-i, LOW);
pauza();
}
}
void StergeCaracterul(int i)
{
int numar;
if (i == 4)
{
for (numar=0; numar<=8 ; numar++)
{
shift.writeBit(numar, LOW);
pauza;
}
}
if (i == 3)
{
for (numar=9; numar<=16 ; numar++)
{
shift.writeBit(numar, LOW);
pauza;
}
}
if (i == 2)
{
for (numar=17; numar<=24 ; numar++)
{
shift.writeBit(numar, LOW);
pauza;
}
}
if (i == 1)
{
for (numar=25; numar<=32 ; numar++)
{
shift.writeBit(numar, LOW);
pauza;
}
}
}
void pauza()
{
delay(IntarziereANIMATIE *10);
}
void unu(int c)
{
if (c == 4)
{
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(3, HIGH);
}
if (c == 3)
{
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(11, HIGH);
}
if (c == 2)
{
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(22, HIGH);
}
if (c == 1)
{
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(30, HIGH);
}
}
void doi(int c)
{
if (c == 4)
{
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(7, HIGH);
pauza();
shift.writeBit(5, HIGH);
pauza();
shift.writeBit(4, HIGH);
}
if (c == 3)
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(15, HIGH);
pauza();
shift.writeBit(13, HIGH);
pauza();
shift.writeBit(12, HIGH);
}
if (c == 2)
{
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(23, HIGH);
pauza();
shift.writeBit(18, HIGH);
pauza();
shift.writeBit(17, HIGH);
}
if (c == 1)
{
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(31, HIGH);
pauza();
shift.writeBit(26, HIGH);
pauza();
shift.writeBit(25, HIGH);
}
}
void trei(int c)
{
if (c == 4)
{
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(7, HIGH);
pauza();
shift.writeBit(3, HIGH);
pauza();
shift.writeBit(4, HIGH);
}
if (c == 3)
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(15, HIGH);
pauza();
shift.writeBit(11, HIGH);
pauza();
shift.writeBit(12, HIGH);
}
if (c == 2)
{
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(23, HIGH);
pauza();
shift.writeBit(22, HIGH);
pauza();
shift.writeBit(17, HIGH);
}
if (c == 1)
{
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(31, HIGH);
pauza();
shift.writeBit(30, HIGH);
pauza();
shift.writeBit(25, HIGH);
}
}
void patru(int c)
{
if (c == 4)
{
shift.writeBit(6, HIGH);
pauza();
shift.writeBit(7, HIGH);
pauza();
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(3, HIGH);
}
if (c == 3)
{
shift.writeBit(14, HIGH);
pauza();
shift.writeBit(15, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(11, HIGH);
}
if (c == 2)
{
shift.writeBit(19, HIGH);
pauza();
shift.writeBit(23, HIGH);
pauza();
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(22, HIGH);
}
if (c == 1)
{
shift.writeBit(27, HIGH);
pauza();
shift.writeBit(31, HIGH);
pauza();
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(30, HIGH);
}
}
void cinci(int c)
{
if (c == 4)
{
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(6, HIGH);
pauza();
shift.writeBit(7, HIGH);
pauza();
shift.writeBit(3, HIGH);
pauza();
shift.writeBit(4, HIGH);
}
if (c == 3)
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(14, HIGH);
pauza();
shift.writeBit(15, HIGH);
pauza();
shift.writeBit(11, HIGH);
pauza();
shift.writeBit(12, HIGH);
}
if (c == 2)
{
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(19, HIGH);
pauza();
shift.writeBit(23, HIGH);
pauza();
shift.writeBit(22, HIGH);
pauza();
shift.writeBit(17, HIGH);
}
if (c == 1)
{
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(27, HIGH);
pauza();
shift.writeBit(31, HIGH);
pauza();
shift.writeBit(30, HIGH);
pauza();
shift.writeBit(25, HIGH);
}
}
void sase(int c)
{
if (c == 4)
{
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(6, HIGH);
pauza();
shift.writeBit(5, HIGH);
pauza();
shift.writeBit(4, HIGH);
pauza();
shift.writeBit(3, HIGH);
pauza();
shift.writeBit(7, HIGH);
}
if (c == 3)
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(14, HIGH);
pauza();
shift.writeBit(13, HIGH);
pauza();
shift.writeBit(12, HIGH);
pauza();
shift.writeBit(11, HIGH);
pauza();
shift.writeBit(15, HIGH);
}
if (c == 2)
{
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(19, HIGH);
pauza();
shift.writeBit(18, HIGH);
pauza();
shift.writeBit(17, HIGH);
pauza();
shift.writeBit(22, HIGH);
pauza();
shift.writeBit(23, HIGH);
}
if (c == 1)
{
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(27, HIGH);
pauza();
shift.writeBit(26, HIGH);
pauza();
shift.writeBit(25, HIGH);
pauza();
shift.writeBit(30, HIGH);
pauza();
shift.writeBit(31, HIGH);
}
}
void sapte(int c)
{
if (c == 4)
{
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(3, HIGH);
}
if (c == 3)
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(11, HIGH);
}
if (c == 2)
{
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(22, HIGH);
}
if (c == 1)
{
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(30, HIGH);
}
}
void opt(int c)
{
if (c == 4)
{
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(3, HIGH);
pauza();
shift.writeBit(4, HIGH);
pauza();
shift.writeBit(5, HIGH);
pauza();
shift.writeBit(6, HIGH);
pauza();
shift.writeBit(7, HIGH);
}
if (c == 3)
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(11, HIGH);
pauza();
shift.writeBit(12, HIGH);
pauza();
shift.writeBit(13, HIGH);
pauza();
shift.writeBit(14, HIGH);
pauza();
shift.writeBit(15, HIGH);
}
if (c == 2)
{
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(22, HIGH);
pauza();
shift.writeBit(17, HIGH);
pauza();
shift.writeBit(18, HIGH);
pauza();
shift.writeBit(19, HIGH);
pauza();
shift.writeBit(23, HIGH);
}
if (c == 1)
{
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(30, HIGH);
pauza();
shift.writeBit(25, HIGH);
pauza();
shift.writeBit(26, HIGH);
pauza();
shift.writeBit(27, HIGH);
pauza();
shift.writeBit(31, HIGH);
}
}
void noua(int c)
{
if (c == 4)
{
shift.writeBit(7, HIGH);
pauza();
shift.writeBit(6, HIGH);
pauza();
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(3, HIGH);
pauza();
shift.writeBit(4, HIGH);
}
if (c == 3)
{
shift.writeBit(15, HIGH);
pauza();
shift.writeBit(14, HIGH);
pauza();
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(11, HIGH);
pauza();
shift.writeBit(12, HIGH);
}
if (c == 2)
{
shift.writeBit(23, HIGH);
pauza();
shift.writeBit(19, HIGH);
pauza();
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(22, HIGH);
pauza();
shift.writeBit(17, HIGH);
}
if (c == 1)
{
shift.writeBit(31, HIGH);
pauza();
shift.writeBit(27, HIGH);
pauza();
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(30, HIGH);
pauza();
shift.writeBit(25, HIGH);
}
}
void zero(int c)
{
if (c == 4)
{
shift.writeBit(1, HIGH);
pauza();
shift.writeBit(2, HIGH);
pauza();
shift.writeBit(3, HIGH);
pauza();
shift.writeBit(4, HIGH);
pauza();
shift.writeBit(5, HIGH);
pauza();
shift.writeBit(6, HIGH);
}
if (c == 3)
{
shift.writeBit(9, HIGH);
pauza();
shift.writeBit(10, HIGH);
pauza();
shift.writeBit(11, HIGH);
pauza();
shift.writeBit(12, HIGH);
pauza();
shift.writeBit(13, HIGH);
pauza();
shift.writeBit(14, HIGH);
}
if (c == 2)
{
shift.writeBit(20, HIGH);
pauza();
shift.writeBit(21, HIGH);
pauza();
shift.writeBit(22, HIGH);
pauza();
shift.writeBit(17, HIGH);
pauza();
shift.writeBit(18, HIGH);
pauza();
shift.writeBit(19, HIGH);
}
if (c == 1)
{
shift.writeBit(28, HIGH);
pauza();
shift.writeBit(29, HIGH);
pauza();
shift.writeBit(30, HIGH);
pauza();
shift.writeBit(25, HIGH);
pauza();
shift.writeBit(26, HIGH);
pauza();
shift.writeBit(27, HIGH);
}
}