Clock with 7 segment indicators on arduino

Hello, I'm new to the world of Arduino, please help with setting the clock at 00:00 (hours: minutes) without an rtc module with a 74HC595 motor register.

If you are not using a rtc , what is the code you have written to do this .
Be aware using the internal timers will not give you and accurate clock.

hammy:
If you are not using a rtc , what is the code you have written to do this .
Be aware using the internal timers will not give you and accurate clock.

unfortunately in the tinker cake there is no rtc:(

here is my code along with the schematic

#include <Wire.h>

#define data_pin 13
#define latch_pin 12
#define clock_pin 11

#define d1_pin 1
#define d2_pin 2
#define d3_pin 3
#define d4_pin 4
#define dot_pin 7
#define btn_pin 9

#define mux_delay 3 // set delay between switching display of digits

byte segments[10] = {
0b00000001, // 0
0b01100111, // 1
0b00010010, // 2
0b01000010, // 3
0b01100100, // 4
0b01001000, // 5
0b00001000, // 6
0b01100011, // 7
0b00000000, // 8
0b01000000 // 9
};

byte segments_off = 0b01111111;

void clearDisplay() {
digitalWrite(d1_pin, LOW);
digitalWrite(d2_pin, LOW);
digitalWrite(d3_pin, LOW);
digitalWrite(d4_pin, LOW);
}

void displayDigit(int digit_pin, int number) {

digitalWrite(latch_pin, LOW);
shiftOut(data_pin, clock_pin, LSBFIRST, segments[number]);
digitalWrite(latch_pin, HIGH);

clearDisplay();

digitalWrite(digit_pin, HIGH);
}

void displayTime(int hours, int minutes) {
int h1, h2, m1, m2;
h2 = hours % 10;
h1 = ((hours % 100) - h1) / 10;
m2 = minutes % 10;
m1 = ((minutes % 100) - m1) / 10;

if (h1==0) {
clearDisplay();
}
else
{
displayDigit(d1_pin, h1);
}
delay(mux_delay);
displayDigit(d2_pin, h2);
delay(mux_delay);
displayDigit(d3_pin, m1);
delay(mux_delay);
displayDigit(d4_pin, m2);
delay(mux_delay);
}

void blinkDot(int seconds) {
if ( (seconds % 2) == 0 ) {
clearDisplay();
digitalWrite(latch_pin, LOW);
shiftOut(data_pin, clock_pin, LSBFIRST, segments_off);
digitalWrite(latch_pin, HIGH);
digitalWrite(d2_pin, HIGH);
digitalWrite(dot_pin, LOW);
} else {
clearDisplay();
digitalWrite(dot_pin, HIGH);
}
delay(mux_delay);
}

void displayDate(int days, int months) {
int d1, d2, m1, m2;
d2 = days % 10;
d1 = ((days % 100) - d1) / 10;
m2 = months % 10;
m1 = ((months % 100) - m1) / 10;
if (d1 == 0) {
clearDisplay();
} else {
displayDigit(d1_pin, d1);
}
delay(mux_delay);
displayDigit(d2_pin, d2);
digitalWrite(dot_pin, LOW);
delay(mux_delay);
digitalWrite(dot_pin, HIGH);
displayDigit(d3_pin, m1);
delay(mux_delay);
displayDigit(d4_pin, m2);
delay(mux_delay);
}

void setup() {

pinMode(data_pin, OUTPUT);
pinMode(latch_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
pinMode(d1_pin, OUTPUT);
pinMode(d2_pin, OUTPUT);
pinMode(d3_pin, OUTPUT);
pinMode(d4_pin, OUTPUT);
pinMode(dot_pin, OUTPUT);
pinMode(btn_pin, INPUT_PULLUP);

Wire.begin();

}

void loop() {

if ( digitalRead(btn_pin) == LOW) {

} else {

}

}

Alex_Lean:
Hello, I'm new to the world of Arduino, please help with setting the clock at 00:00 (hours: minutes) without an rtc module with a 74HC595 motor register.

What clock are you using? Is it an actual clock that keeps time, or is it just a digital display for a clock?

Alex_Lean:
unfortunately in the tinker cake there is no rtc:(

What "tinker cake" is this? Can you provide a link to a Web site for it?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Unfortunately the circuit diagram did not take.

Thanks.. Tom... :slight_smile: