int latchPin = 5;
int clockPin = 18;
int dataPin = 23;
uint8_t _hours = 0;
uint8_t _secs = 0;
uint8_t _mins = 0;
void setup() {
Serial.begin(115200);
pinMode(clockPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
danceBitch();
delay(10);
}
uint64_t then = 0;
void danceBitch()
{
uint64_t now = millis();
if(now > (then + 1000))
{
then = now;
uint8_t flashLevel = 0;
if(++_secs > 59)
{
_secs = 0;
flashLevel++;
if(++_mins > 59)
{
_mins = 0;
flashLevel++;
if(++_hours > 23)
{
_hours = 0;
flashLevel++;
}
}
}
switch(flashLevel) {
case 3:
writeTime(31, 63, 63);
break;
case 2:
writeTime(_hours, 63, 63);
break;
case 1:
writeTime(_hours, _mins, 63);
break;
default:
writeTime(_hours, _mins, _secs);
break;
}
if(flashLevel > 0)
{
flashLevel = 0;
delay(350);
writeTime(_hours, _mins, _secs);
}
}
}
void writeTime(uint8_t hours, uint8_t mins, uint8_t secs)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, secs);
shiftOut(dataPin, clockPin, LSBFIRST, mins);
// shiftOut(dataPin, clockPin, LSBFIRST, hours);
digitalWrite(latchPin, HIGH);
}