jeremy-daily
New member
I've created a simple sketch that provides a way to get microseconds in a timestamp. I'm interested in any alternatives.
Does the setSyncInterval() function create an interrupt so the microsecond reset counter is always called on time?
Does the setSyncInterval() function create an interrupt so the microsecond reset counter is always called on time?
Code:
#include <TimeLib.h>
elapsedMicros microsecondsPerSecond;
time_t getTeensy3Time(){
microsecondsPerSecond = 0; // Reset the microsecond timer
return Teensy3Clock.get();
}
void setup() {
// put your setup code here, to run once:
setSyncProvider(getTeensy3Time);
setSyncInterval(1); //must be on a 1 second interval to get the microseconds to sync.
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
char timeString[22];
sprintf(timeString,"%04d-%02d-%02d %02d:%02d:%02d.%06d",year(),month(),day(),hour(),minute(),second(),uint32_t(microsecondsPerSecond));
Serial.println(timeString);
}