From 1beadda3df85ed0b9ee8293d1519698c2df7bc7f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 12 Dec 2023 08:24:49 +0100 Subject: [PATCH] Fix: Increase accuracy of "delay()" routine. This fixes #194. --- cores/arduino/time.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cores/arduino/time.cpp b/cores/arduino/time.cpp index 8fc9a2e08..c5269c928 100644 --- a/cores/arduino/time.cpp +++ b/cores/arduino/time.cpp @@ -4,8 +4,11 @@ // this file implements the following public funcions: delay, delayMicroseconds, yield, millis, micros -__attribute__((weak)) void delay(uint32_t ms) { - R_BSP_SoftwareDelay(ms, BSP_DELAY_UNITS_MILLISECONDS); +__attribute__((weak)) void delay(uint32_t ms) +{ + auto const start = millis(); + auto const stop = start + ms; + while(millis() < stop) yield(); } void delayMicroseconds(unsigned int us) {