Hodiny mi fungují krásně v serial mám výstup
Kód: Vybrat vše
11:00:40.767 -> Neděle 06-09-2020 11:01:00
Kód: Vybrat vše
// Example sketch for interfacing with the DS1302 timekeeping chip.
//
// Copyright (c) 2009, Matt Sparks
// All rights reserved.
//
// http://quadpoint.org/projects/arduino-ds1302
#include <stdio.h>
#include <DS1302.h>
namespace {
// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip. See the DS1302
// datasheet:
//
// http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
const int kCePin = 5; // Chip Enable
const int kIoPin = 6; // Input/Output
const int kSclkPin = 7; // Serial Clock
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Neděle";
case Time::kMonday: return "Pondělí";
case Time::kTuesday: return "Úterý";
case Time::kWednesday: return "Středa";
case Time::kThursday: return "Čtvrtek";
case Time::kFriday: return "Pátek";
case Time::kSaturday: return "Sobota";
}
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 %02d-%02d-%04d %02d:%02d:%02d",
day.c_str(),
t.date, t.mon, t.yr,
t.hr, t.min, t.sec);
// Print the formatted string to serial so we can see the time.
Serial.println(buf);
}
} // namespace
void setup() {
Serial.begin(9600);
pinMode(3, OUTPUT);
// 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.
rtc.writeProtect(false);
rtc.halt(false);
// Make a new time object to set the date and time.
// Sunday, September 22, 2013 at 01:38:50.
// Time t(2020, 9, 5, 16, 29, 50, Time::kSaturday);
// Set the time and date on the chip.
// rtc.time(t);
}
// Loop and print the time every second.
void loop() {
printTime();
// Sepnuti led
// if ( (t.hr == 15) && (t.min == 8) && (t.sec == 0) ) { digitalWrite(3, HIGH ); };
// Vypnuti led
// if ( (t.hr == 15) && (t.min == 9) && (t.sec == 0) ) { digitalWrite(3, LOW ); };
delay(1000);
}