aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2010-05-25 20:16:15 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2010-05-25 20:16:15 +0000
commit67c0a1995aace2953e481ef6183b1b91e04942fc (patch)
treefba7699687976ed49def0841a3bd95a600e73999 /cores/arduino
parent04475f4bfed43d3e956ffeb28e8aa4b552f922f7 (diff)
More accurate delay() function from BenF.
Diffstat (limited to 'cores/arduino')
-rwxr-xr-xcores/arduino/wiring.c12
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. */