Skip to content

Commit 03c68c9

Browse files
committed
fix delay/yield avr
1 parent d893aa0 commit 03c68c9

File tree

1 file changed

+9
-9
lines changed
  • hardware/arduino/avr/cores/arduino

1 file changed

+9
-9
lines changed

hardware/arduino/avr/cores/arduino/wiring.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ unsigned long micros() {
105105

106106
void delay(unsigned long ms)
107107
{
108-
uint16_t start = (uint16_t)micros();
109-
110-
while (ms > 0) {
111-
yield();
112-
if (((uint16_t)micros() - start) >= 1000) {
113-
ms--;
114-
start += 1000;
115-
}
116-
}
108+
uint32_t start = (uint32_t)micros();
109+
110+
while (ms > 0) {
111+
yield();
112+
while ( ms > 0 && ((uint32_t)micros() - start) >= 1000) {
113+
ms--;
114+
start += 1000;
115+
}
116+
}
117117
}
118118

119119
/* Delay for the given number of microseconds. Assumes a 1, 8, 12, 16, 20 or 24 MHz clock. */

0 commit comments

Comments
 (0)