I have a T-Display S3 and a BME280 sensor module and want to log the temperature every ten minutes.
I use PlatformIO and the Arduino framework.
Could someone please advise me on the best way to accomplish this?
Thank you for any help
I don’t know if this is the best way, but I would do it this way:
void logTemperature() {
Serial.println("Current temperature is...");
}
void logTemperatureEveryTenMinutes() {
static uint32_t last_millis;
uint32_t current_millis = millis();
const uint32_t ten_minutes_in_milliseconds = 10 * 60 * 1000;
const uint32_t elapsed_milliseconds = current_millis - last_millis;
if (last_millis && elapsed_milliseconds < ten_minutes_in_milliseconds) return;
last_millis = current_millis;
logTemperature();
}
void loop() {
logTemperatureEveryTenMinutes();
}
I think you hit the nail on the head.
This way I can do a couple of other things (check buttons, choose pressure temperature or humidity to display etc.) while I’m waiting for the next measurement.
I never used the millis() function, didn’t know it existed thank you sivar 2311.
If there are other ways of doing this, I’m still interested
Greetings Bert
Sorry, but this era of code is ECO disaster. MCU do nothink on max speed only eat power. Try learn deep sleep and RTC
I think your reply would be more helpful if you included an example. Many people who read these threads are looking for solutions and trying to learn as they go along.
Copy existing is next ECO disaster … esp32 deep sleep rtc adc - Google Search