Skip to content

Commit 67c0a19

Browse files
committed
More accurate delay() function from BenF.
1 parent 04475f4 commit 67c0a19

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cores/arduino/wiring.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ unsigned long micros() {
9797

9898
void delay(unsigned long ms)
9999
{
100-
unsigned long start = millis();
101-
102-
while (millis() - start <= ms)
103-
;
100+
uint16_t start = (uint16_t)micros();
101+
102+
while (ms > 0) {
103+
if (((uint16_t)micros() - start) >= 1000) {
104+
ms--;
105+
start += 1000;
106+
}
107+
}
104108
}
105109

106110
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */

0 commit comments

Comments
 (0)