RTC DS1302

Za mjerenje vremena možemo koristiti različite module……

za ovaj smo se morali pomučiti najviše dok smo pronašli valjanu biblioteku i primjer programa:

link na biblioteku

i primjer programa:

// Example sketch for interfacing with the DS1302 timekeeping chip.
// Copyright (c) 2009, Matt Sparks
// All rights reserved.

#include <stdio.h>
#include <DS1302.h>
namespace {

// http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
const int kCePin = 8; // Chip Enable
const int kIoPin = 7; // Input/Output
const int kSclkPin = 6; // Serial Clock

// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);

String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return “Nedjelja”;
case Time::kMonday: return “Ponedjeljak”;
case Time::kTuesday: return “Utorak”;
case Time::kWednesday: return “Srijeda”;
case Time::kThursday: return “Cetvrtak”;
case Time::kFriday: return “Petak”;
case Time::kSaturday: return “Subota”;
return “(unknown day)”;

void printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();

// Name the day of the week.
const String day = dayAsString(t.day);

// Format the time and date and insert into the temporary buffer.
char buf[50];
snprintf(buf, sizeof(buf), “%s %04d-%02d-%02d %02d:%02d:%02d”,
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);

// Print the formatted string to serial so we can see the time.

} // namespace

void setup() {
// Initialize a new chip by turning off write protection and clearing the
// clock halt flag. These methods needn’t always be called. See the DS1302
// datasheet for details.

// promjena vremena i datuma
// Sunday, September 22, 2013 at 01:38:50.
// Time t(2018, 3, 17, 23, 07, 50, Time::kSaturday);
// zapisivanje novog vremena na cip

//ispisuje vrijeme svake sekunde
void loop() {