1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-27 21:54:30 +01:00

More accurate delay() function from BenF.

This commit is contained in:
David A. Mellis 2010-05-25 20:16:15 +00:00
parent 9f755fd414
commit 8f416eb54a

View File

@ -97,10 +97,14 @@ unsigned long micros() {
void delay(unsigned long ms) void delay(unsigned long ms)
{ {
unsigned long start = millis(); uint16_t start = (uint16_t)micros();
while (millis() - start <= ms) while (ms > 0) {
; if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
} }
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */ /* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */