Page 1 of 1

Call a function once a second using the time() library?

Posted: Sat Mar 03, 2018 8:36 pm
by Dillon1337
My code is heavily based on this example of receiving the time from the internet: https://github.com/espressif/arduino-es ... leTime.ino I'd like to call a function whenever the second increments. I'm using

Code: Select all

time(NULL)
to get the time and it's counting up in the background, so I'm wondering if there's something there that I can attach an interrupt to. Is this possible?

My alternative is to create a one second hardware timer interrupt and call the function there but I'd rather have my function exactly track the time.

Thanks in advance!
Dillon

Re: Call a function once a second using the time() library?

Posted: Mon Mar 12, 2018 7:08 pm
by kolban
I'm wondering (out loud) if this library might serve you:

Simple Timer

It claims to have both a setInterval() and a setTimeout() pair of functions that take a callback function and a duration.

Re: Call a function once a second using the time() library?

Posted: Mon Mar 12, 2018 7:41 pm
by Dillon1337
It might work - thanks for the response. I'm unable to tell if it's blocking or not. I want to run other code in the foreground of the while loop.

I was able to make something work using a hardware timer (https://github.com/dwaq/Super7Seg/blob/ ... no#L31-L43), but ideally I would like to base something entirely on the time.h library (https://github.com/dwaq/Super7Seg/blob/ ... pp#L70-L80). I think it might be a linux/ RTOS standard, so maybe I'm better off asking someone with expertise on that topic.