Hallo,
wieder mal ne blöde Frage wie so oft.
Ist es möglich in der RTClib, now.minute() einen Integer Wert zuzuweisen?
Die Libary sagt:
class DateTime {
public:
DateTime(uint32_t t = SECONDS_FROM_1970_TO_2000);
DateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour = 0,
uint8_t min = 0, uint8_t sec = 0);
DateTime(const DateTime ©);
DateTime(const char *date, const char *time);
DateTime(const __FlashStringHelper *date, const __FlashStringHelper *time);
DateTime(const char *iso8601date);
bool isValid() const;
char *toString(char *buffer) const;
.
.
.
.
uint8_t minute() const { return mm; }
/*!
@brief Return the second.
@return Second (0--59).
*/
Soweit ich das vertsehe nicht, da es const ist oder?
Geht mir um den sqw Pin vom DS3231 für einen Interrupt:
Hier mein Code und was ich machen will:
/* Example implementation of an alarm using DS3231
VCC and GND of RTC should be connected to some power source
SDA, SCL of RTC should be connected to SDA, SCL of arduino
SQW should be connected to CLOCK_INTERRUPT_PIN
CLOCK_INTERRUPT_PIN needs to work with interrupts
*/
#include <RTClib.h>
// #include <Wire.h>
RTC_DS3231 rtc;
int interval = 2;
DateTime now;
int mins;
int timex;
// the pin that is connected to SQW
#define CLOCK_INTERRUPT_PIN 2
void setup() {
Serial.begin(9600);
// initializing the rtc
if (!rtc.begin()) {
Serial.println("Couldn't find RTC!");
Serial.flush();
abort();
}
if (rtc.lostPower()) {
// this will adjust to the date and time at compilation
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
//we don't need the 32K Pin, so disable it
rtc.disable32K();
// Making it so, that the alarm will trigger an interrupt
pinMode(CLOCK_INTERRUPT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(CLOCK_INTERRUPT_PIN), onAlarm, FALLING);
// set alarm 1, 2 flag to false (so alarm 1, 2 didn't happen so far)
// if not done, this easily leads to problems, as both register aren't reset on reboot/recompile
rtc.clearAlarm(1);
rtc.clearAlarm(2);
// stop oscillating signals at SQW Pin
// otherwise setAlarm1 will fail
rtc.writeSqwPinMode(DS3231_OFF);
// turn off alarm 2 (in case it isn't off already)
// again, this isn't done at reboot, so a previously set alarm could easily go overlooked
rtc.disableAlarm(2);
now = rtc.now();
mins = now.minute();
mins = mins + interval;
mins = mins % 60;
now.minute = mins;
// schedule an alarm 10 seconds in the future
if (!rtc.setAlarm1(now, DS3231_A1_Minutes // this mode triggers the alarm when the seconds match. See Doxygen for other options
)) {
Serial.println("Error, alarm wasn't set!");
} else {
Serial.println("Alarm will happen in xx seconds!");
}
}
void loop() {
// print current time
char date[10] = "hh:mm:ss";
rtc.now().toString(date);
Serial.print(date);
// the value at SQW-Pin (because of pullup 1 means no alarm)
Serial.print(" SQW: ");
Serial.print(digitalRead(CLOCK_INTERRUPT_PIN));
// whether a alarm happened happened
Serial.print(" Alarm1: ");
Serial.print(rtc.alarmFired(1));
// Serial.print(" Alarm2: ");
// Serial.println(rtc.alarmFired(2));
// control register values (see https://datasheets.maximintegrated.com/en/ds/DS3231.pdf page 13)
// Serial.print(" Control: 0b");
// Serial.println(read_i2c_register(DS3231_ADDRESS, DS3231_CONTROL), BIN);
// resetting SQW and alarm 1 flag
// using setAlarm1, the next alarm could now be configurated
if (rtc.alarmFired(1)) {
rtc.clearAlarm(1);
Serial.println("Alarm cleared");
Serial.println("Bew Alarm");
mins = mins + interval;
if (mins >= 60) mins = mins - 60;
now.minute() = mins;
if (!rtc.setAlarm1(now, DS3231_A1_Minutes // this mode triggers the alarm when the seconds match. See Doxygen for other options
)) {
Serial.println("Error, alarm wasn't set!");
} else {
Serial.println("Alarm will happen in xx seconds!");
}
}
delay(2000);
}
void onAlarm() {
Serial.println("Alarm occured!");
}
/*static uint8_t read_i2c_register(uint8_t addr, uint8_t reg) {
Wire.beginTransmission(addr);
Wire.write((byte)reg);
Wire.endTransmission();
Wire.requestFrom(addr, (byte)1);
return Wire.read();
}*/
Danke an jeden der sich die Zeit nimmt mir zu helfen!
Schönen Tag
Lg