01-18-2024 03:45 PM
Use of delay() in Arduino code is universally considered bad practice. The better approach is to test a duration in millis.
Looking at the code in the provided libraries in BSEC_Arduino_Library, I note, in bsec.cpp, the function void Bsec::delay_us(uint32_t period, void *intfPtr). This function uses delay(). The use of delay() in bsec.cpp interferes with the timing of code in loop() if a call is made to the run() method.
Has anyone reimplemented bsec.cpp to avoid use of delay()? I plan on doing so, but do not want to "reinvent the wheel" if I can avoid that.
Thanks to all in advance.
Solved! Go to Solution.
01-19-2024 07:21 AM
Hi mgchristensen,
In bsec.cpp, the delay_us() function has been adapted to the millisecond delay to microsecond delay of the delay() function.
/**
@brief Task that delays for a us period of time
*/
void Bsec::delay_us(uint32_t period, void *intfPtr)
{
(void) intfPtr;
// Wait for a period amount of ms
// The system may simply idle, sleep or even perform background tasks
delay(period/1000);
}
01-19-2024 02:18 PM
Thank you for your reply! I clicked accept as solution in error, and my reply was dumped into the bit bucket.
The line delay(period/1000); is precisely what the problem is. I will post again with a better explanation.