diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2010-05-25 20:16:15 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2010-05-25 20:16:15 +0000 |
commit | 67c0a1995aace2953e481ef6183b1b91e04942fc (patch) | |
tree | fba7699687976ed49def0841a3bd95a600e73999 | |
parent | 04475f4bfed43d3e956ffeb28e8aa4b552f922f7 (diff) |
More accurate delay() function from BenF.
-rwxr-xr-x | cores/arduino/wiring.c | 12 |
1 files changed, 8 insertions, 4 deletions
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. */ |