RED HAT
RED HAT
How to delay() easily when you don't have delay()?
sorry for some of the blunders english is not my first language
8 replies
How to delay() easily when you don't have delay()?
you can use alternatives like usleep or nanosleep in C (POSIX Systems), HAL_Delay in STM32 HAL Library, and std::this_thread::sleep_for in C++1 depending on which is more compatible with your program
8 replies
How to delay() easily when you don't have delay()?
@Navadeep there are many disadvantages for using a for loop as you just did like, The actual delay duration can vary depending on the compiler optimization settings and the CPU speed. this means the delay might not be consistent across different systems or even different runs on the same system, The for loop delay is a busy-wait loop, meaning the CPU is doing nothing useful during this time but still consuming power. this can be inefficient, especially in battery-powered or resource-constrained environments, External factors like interrupts or other high-priority tasks can affect the timing, making this method non-deterministic in real-time applications and This approach is not scalable for longer delays or more complex timing requirements.
8 replies