Hello everyone, I hope for your great minds and responsiveness.
So, the background: The idea came to my wife for a present - a frame that shows how many years, months and days we are together, and on the same board there is a second counter that shows how many days are in total together. In theory, everything is simple, the clock on the DS1307 and the difference in dates are displayed on the 7-segment display.
Links to the video of the finished device:
I ordered the boards, printed the case, and then the weak point = firmware. Here I copied everything from any examples, tried to figure it out and combine everything into one, and with my knowledge that was equal to zero, I realized what I had conceived, but with one problem it was a visible switching between indicators, that is, changing the delay values at the end of the code I clearly see how fast or slower they switch. If I set the value already in delayMicroseconds starts to fade the display and only one digit shines clearly.
I collected everything in a proteus, there I tested it in a simulation.
It turns out indicators with a common anode, all on transistors.
#include <Wire.h> //Libraries to communicate with RTC
#include "RTClib.h"
RTC_DS1307 rtc; //create rtc object
int segs[] = {0, 1, 2, 3, 4, 5, 6, 7}; //abcdefg. segments
int digits[] = {12, 13, 10, 11, 8, 9}; //number of digits
byte num[] = { B11000000, B11111001, B10100100, B10110000, B10011001, B10010010, B10000010, B11111000, B10000000, B10010000 };
int t, dm, Y, M ,D;
DateTime dob = DateTime(2010, 6, 27, 0, 0, 0);
int t0 = dob.year() * 12 + dob.month() - 1;
void setup()
{
rtc.begin(); //begin rtc communication
//rtc.adjust(DateTime(2019, 12, 23, 20, 04, 0));
for (int i = 0; i < 8; i++)
{
pinMode(segs[i], OUTPUT);//set segment pins output
}
for (int i = 0; i < 6; i++)
{
pinMode(digits[i], OUTPUT);//set digts as outputs
}
}
void loop()
{
DateTime now = rtc.now();
t = now.year() * 12 + now.month() - 1;
dm = t - t0;
if (now.day() >= dob.day()) {
Y = floor(dm / 12);
M = dm % 12;
D = now.day() - dob.day();
} else {
dm--;
t--;
Y = floor(dm / 12);
M = dm % 12;
DateTime tmp = DateTime(floor(t / 12), (t % 12) + 1, dob.day(), 0, 0, 0);
D = (now.unixtime() - tmp.unixtime()) / 60 / 60 / 24;
}
printTime(D, M, Y);
}
void printNum(int number) //function to print number
{
byte data = num[number];
for (int i = 0; i < 8; i++)
{
if (data & 0x01)
digitalWrite(segs[i], HIGH);
else
digitalWrite(segs[i], LOW);
data >>= 1;
}
}
void printTime(int D, int M, int Y)
{
int d[] = { floor(D / 10), D - 10 * floor(D / 10), floor(M / 10), M - 10 * floor(M / 10), floor(Y / 10), Y - 10 * floor(Y / 10) };
for (int i = 0; i < 6; i++)
{
if (i == 0) digitalWrite(digits[5], LOW);
if (i != 0) digitalWrite(digits[i - 1], LOW);
digitalWrite(digits[i], HIGH);
printNum(d[i]);
delay(1);
}
}



