From 67c0a1995aace2953e481ef6183b1b91e04942fc Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Tue, 25 May 2010 20:16:15 +0000 Subject: More accurate delay() function from BenF. --- cores/arduino/wiring.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cores/arduino/wiring.c') diff --git a/cores/arduino/wiring.c b/cores/arduino/wiring.c index 858ab72..719e0e2 100755 --- a/cores/arduino/wiring.c +++ b/cores/arduino/wiring.c @@ -97,10 +97,14 @@ unsigned long micros() { void delay(unsigned long ms) { - unsigned long start = millis(); - - while (millis() - start <= ms) - ; + uint16_t start = (uint16_t)micros(); + + 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. */ -- cgit v1.2.3-18-g5258