Hello,
I’m already sorry for my mistakes, I’m french.
I got a code on the internet to link my digit (4 digit of 7 bytes) with my clock DS1307 V03, and my problem is, the first number of the clock (for example 10h23m, he’ll take 1 for the all digit), so I’ve checked the code for trying to figure it out, I think the problem is due to the transmission, right here :
void sendSerialData (byte registerCount, byte *pValueArray) {
// Signal to the 595s to listen for data
digitalWrite (g_pinCommLatch, LOW);
for (byte reg = registerCount; reg > 0; reg--)
{
byte value = pValueArray [reg - 1];
for (byte bitMask = 128; bitMask > 0; bitMask >>= 1)
{
digitalWrite (g_pinClock, LOW);
digitalWrite (g_pinData, value & bitMask ? HIGH : LOW);
digitalWrite (g_pinClock, HIGH);
}
}
// Signal to the 595s that I'm done sending
digitalWrite (g_pinCommLatch, HIGH);
} // sendSerialData
And here the full code :
#include <Wire.h>
#include "RTClib.h"
const int g_pinData = 8;
const int g_pinCommLatch = 9;
const int g_pinClock = 10;
RTC_DS1307 RTC; // define RTC variables
byte g_digits [7]; // Definitions of the 7-bit values for displaying digits
int g_numberToDisplay = 0; // default number being displayed, 0
const int g_registers = 4; // Number of shift registers in use, 4
byte g_registerArray [g_registers]; // Array of numbers to pass to shift registers
void setup()
{
// I2C RTC Setup
Wire.begin();
RTC.begin();
/* Only set the time on compile if the RTC is not running...
This is used to set the current time from the computer clock
if ( !RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
*/
pinMode (g_pinCommLatch, OUTPUT); // define 74595 pins as output
pinMode (g_pinClock, OUTPUT); // define 74595 pins as output
pinMode (g_pinData, OUTPUT); // define 74595 pins as output
Serial.begin (9600); // optional, turn on serial monitoring for debugging
// Setup 7 segment display for number 0 to 9 and other characters
// a - top bar
// b - top right
// c - bottom right
// d - bottom bar
// e - bottom left
// f - top right
// g - middle bar
int a = 1, b = 2, c = 4, d = 8, e = 16, f = 32, g = 64;
g_digits [0] = a + b + c + d + e + f;
g_digits [1] = b + c;
g_digits [2] = a + b + g + e + d;
g_digits [3] = a + b + g + c + d;
g_digits [4] = f + g + b + c;
g_digits [5] = a + f + g + c + d;
g_digits [6] = a + f + g + c + d + e;
g_digits [7] = a + b + c;
g_digits [8] = a + b + c + d + e + f + g;
g_digits [9] = a + b + c + d + g + f;
g_digits [90] = a + b + g + f; // Degree dot
g_digits [91] = a + f + e + d; // Capital C
g_digits [92] = e + g; // r, 80
g_digits [93] = f + e + g + c; // h, 116
g_digits [99] = 0;
} // End of setup() //
// Simple function to send serial data to one or more shift registers by iterating backwards through an array.
// Although g_registers exists, they may not all be being used, hence the input parameter.
void sendSerialData (byte registerCount, byte *pValueArray) {
// Signal to the 595s to listen for data
digitalWrite (g_pinCommLatch, LOW);
for (byte reg = registerCount; reg > 0; reg--)
{
byte value = pValueArray [reg - 1];
for (byte bitMask = 128; bitMask > 0; bitMask >>= 1)
{
digitalWrite (g_pinClock, LOW);
digitalWrite (g_pinData, value & bitMask ? HIGH : LOW);
digitalWrite (g_pinClock, HIGH);
}
}
// Signal to the 595s that I'm done sending
digitalWrite (g_pinCommLatch, HIGH);
} // sendSerialData
// ====================== Main loop() =======================
void loop()
{
int hour,minute,disp= 0;
DateTime now = RTC.now(); // Get current time & date
hour = now.hour(); // break down time to hour
minute = now.minute(); // break down time to minute
/* Serial output debugging for the date & time
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
*/
delay(1000);
Serial.print(hour);
Serial.print(':');
Serial.print(minute);
Serial.println();
// Push the hour 2 digits to the left by multiplying 100
disp = (hour * 100) + minute;
// Push the numbers to the four digits
if (disp < 10)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [2] = g_digits [0];
g_registerArray [3] = g_digits [disp];
}
else if (disp < 60)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [0];
g_registerArray [2] = g_digits [disp / 10];
g_registerArray [3] = g_digits [disp % 10];
}
else if (disp < 960)
{
g_registerArray [0] = g_digits [0];
g_registerArray [1] = g_digits [disp / 100];
g_registerArray [2] = g_digits [(disp % 100) / 10];
g_registerArray [3] = g_digits [disp % 10];
}
else
{
g_registerArray [0] = g_digits [disp / 1000];
g_registerArray [1] = g_digits [(disp % 1000) / 100];
g_registerArray [2] = g_digits [(disp % 100) / 10];
g_registerArray [3] = g_digits [disp % 10];
}
sendSerialData (g_registers, g_registerArray);
} // end of loop
I’m a beginner and I’d glad to make a handmade alarm clock. If you want more photo or other thing, just ask me
Have a good day !