int dataPin = 2; //IC 14 //Define which pins will be used for the Shift Register control
int latchPin = 3; //IC 12
int clockPin = 4; //IC 11
//OE-GND
//MR-VCC
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 10; // interval at which to blink (milliseconds)
int del = 10;
int columns = 0;
int counter = 10000;
int m = 1;
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
static uint8_t numbers [80] = //numbers stored here
{
0x00, 0x7c, 0xa2, 0x92, 0x8a, 0x7c, 0x00, 0x00, // 0
0x00, 0x42, 0xfe, 0x02, 0x00, 0x00, 0x00, 0x00, // 1
0x00, 0x42, 0x86, 0x8a, 0x92, 0x62, 0x00, 0x00, // 2
0x00, 0x84, 0x82, 0xa2, 0xd2, 0x8c, 0x00, 0x00, // 3
0x00, 0x18, 0x28, 0x48, 0xfe, 0x08, 0x00, 0x00, // 4
0x00, 0xe4, 0xa2, 0xa2, 0xa2, 0x9c, 0x00, 0x00, // 5
0x00, 0x3c, 0x52, 0x92, 0x92, 0x0c, 0x00, 0x00, // 6
0x00, 0x80, 0x8e, 0x90, 0xa0, 0xc0, 0x00, 0x00, // 7
0x00, 0x6c, 0x92, 0x92, 0x92, 0x6c, 0x00, 0x00, // 8
0x00, 0x60, 0x92, 0x92, 0x94, 0x78, 0x00, 0x00, // 9
};
void setup()
{
Wire.begin();
RTC.begin();
DDRD = DDRD | B00011100; //set pins as output
}
void loop()
{
DateTime now = RTC.now();
unsigned long currentMillis = millis(); //take value from millis() each loop
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if (counter == 0)
{
counter = 10; //reset to start
}
else
counter--; //if not 0, keep on counting
}
columns++; //at each loop run, increment by one
if (columns > 8)
{
columns = 0; //if counter exceeds 8, reset it
}
PORTD = B00000000; //turn latch low
shiftOut(dataPin, clockPin, MSBFIRST, 1 << columns); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
pickNumber((now.minute() / m / 1) % 10); //ones
PORTD = B00001000; //turn latch on->show screen
PORTD = B00000000; //turn latch low
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, 1 << columns); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
pickNumber((now.minute() / m / 10) % 10); //tens
PORTD = B00001000; //turn latch on->show screen
PORTD = B00000000; //turn latch low
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, 1 << columns); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
pickNumber((now.hour() / m / 1) % 10); //hundreds
PORTD = B00001000; //turn latch on->show screen
PORTD = B00000000; //turn latch low
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //Send the data #2 (what columns to power)
shiftOut(dataPin, clockPin, MSBFIRST, 1 << columns); //Send the data #2 (what columns to power)
pickNumber((now.hour() / m / 10) % 10); //thousands
PORTD = B00001000; //turn latch on->show screen
}
void pickNumber( int count) //pick numbers from array, at start of whole code
{
switch (count)
{
case 1: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 8]); break; //0
case 2: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 16]); break; //1
case 3: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 24]); break; //2
case 4: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 32]); break; //3
case 5: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 40]); break; //4
case 6: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 48]); break; //5
case 7: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 56]); break; //6
case 8: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 64]); break; //7
case 9: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 72]); break; //8
case 10: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 80]); break; //9
default: shiftOut(dataPin, clockPin, LSBFIRST, numbers[columns + 0]); break; //9
}
}