Dit is de code die ik tot nu toe gevonden heb:
// CONNECTIONS:
// DS1302 CLK/SCLK → 5
// DS1302 DAT/IO → 4
// DS1302 RST/CE → 2
// DS1302 VCC → 3.3v - 5v
// DS1302 GND → GND
int pinA = 0;
int pinB = 1;
int pinC = 3;
int pinD = 6;
int pinE = 7;
int pinF = 8;
int pinG = 9;
int D1 = 13;
int D2 = 12;
int D3 = 11;
int D4 = 10;
#include <ThreeWire.h>
#include <RtcDS1302.h>
ThreeWire myWire(4,5,2); // IO, SCLK, CE
RtcDS1302 Rtc(myWire);
void setup ()
{
Serial.begin(57600);
Serial.print("compiled: ");
Serial.print(DATE);
Serial.println(TIME);
Rtc.Begin();
RtcDateTime compiled = RtcDateTime(DATE, TIME);
printDateTime(compiled);
Serial.println();
if (!Rtc.IsDateTimeValid())
{
// Common Causes:
// 1) first time you ran and the device wasn’t running yet
// 2) the battery on the device is low or even missing
Serial.println(“RTC lost confidence in the DateTime!”);
Rtc.SetDateTime(compiled);
}
if (Rtc.GetIsWriteProtected())
{
Serial.println(“RTC was write protected, enabling writing now”);
Rtc.SetIsWriteProtected(false);
}
if (!Rtc.GetIsRunning())
{
Serial.println(“RTC was not actively running, starting now”);
Rtc.SetIsRunning(true);
}
RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println(“RTC is older than compile time! (Updating DateTime)”);
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println(“RTC is newer than compile time. (this is expected)”);
}
else if (now == compiled)
{
Serial.println(“RTC is the same as compile time! (not expected but all is fine)”);
}
pinMode(pinA,OUTPUT);
pinMode(pinB,OUTPUT);
pinMode(pinC,OUTPUT);
pinMode(pinD,OUTPUT);
pinMode(pinE,OUTPUT);
pinMode(pinF,OUTPUT);
pinMode(pinG,OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
}
void loop ()
{
RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
Serial.println();
if (!now.IsValid())
{
// Common Causes:
// 1) the battery on the device is low or even missing and the power line was disconnected
Serial.println(“RTC lost confidence in the DateTime!”);
}
delay(10000); // ten seconds
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}
Kan iemand mij helpen hoe ik nu mijn klok op mijn 4 digit 7 segment display kan tonen?
Alvast bedankt!