This code is printing the current time and temperature in Fahrenheit no problem, but the time in milli seconds is not going up even when I have the SQW wired to pin 32. Here is the code and output below:
Code:
Code: Select all
#include "RTClib.h"
RTC_DS3231 rtc;
int interrupt_pin = 32;
int current = 0;
int milliseconds = 0;
void IRAM_ATTR function()
{
milliseconds = millis() - current;
current = millis();
}
void setup() {
Serial.begin(9600);
rtc.begin();
pinMode(interrupt_pin, INPUT_PULLUP);
attachInterrupt(interrupt_pin, function, FALLING);
// Set the time to 11:30 AM
rtc.adjust(DateTime(__DATE__, __TIME__));
rtc.adjust(DateTime(0, 0, 0, 11, 20, 0)); // Set the desired time here
}
void loop() {
DateTime now = rtc.now();
// Display time
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print('.');
Serial.print(milliseconds);
float temperatureC = rtc.getTemperature();
float temperatureF = (temperatureC * 9 / 5) + 32; // Convert Celsius to Fahrenheit
Serial.print(" ");
Serial.println(temperatureF);
}
Output:
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:42.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30
11:20:43.0 74.30