Help with max and average result in last 24 hours

Hi everyone,

I am lost as to where to look and start trying to get a section of code for showing a max result in the past x-amount of time.

For example i am programming a Co2 monitor for my office space, and on the LCD / Serial monitor i want it to display the highest PPM recorded in the last hour or 24 hours, aswell as the average over 24 hours. I have all the display code sorted just stuck on this one part.

I am unsure as to how i will implement this with my RTC as i assume it will need to roll over the integer every hour/24 hours?

Any direction would be appreciated, i am aware this is rather vague but can't see any other examples as i don't know what i am looking for.

Cheers in advance.

Welcome to the forum!

Most people do this with a "circular buffer" or queue that contains only the last 24 hours of data. Google those terms for code examples.

The size of that buffer (array) is limited on most Arduinos, so choose your sample rate carefully.

1 Like

Thanks mate that's a lot of help!

this looks to be the go.

~BrokenTrace

To launch an event on some time rollover:

currentHour = getHour
if (currentHour != previousHour) {
  previousHour = currentHour
  if (currentHour == alarmHour) {
    launch event
  }
}

Your event is "rolling over an integer".

1 Like

This is also super helpful,
I appreciate the help!