Skip to content

Commit 3b6466b

Browse files
Rocketctsandeepmistry
authored andcommitted
More accurate delay() function from BenF.
porting of arduino/ArduinoCore-avr@67c0a19#diff-ab397febf179e1982f4ee0758df4c982
1 parent 97502e9 commit 3b6466b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cores/arduino/delay.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,22 @@ unsigned long micros( void )
6363

6464
void delay( unsigned long ms )
6565
{
66-
if ( ms == 0 )
66+
if (ms == 0)
6767
{
68-
return ;
68+
return;
6969
}
7070

71-
uint32_t start = _ulTickCount ;
71+
uint32_t start = micros();
7272

73-
do
73+
while (ms > 0)
7474
{
75-
yield() ;
76-
} while ( _ulTickCount - start < ms ) ;
75+
yield();
76+
while (ms > 0 && (micros() - start) >= 1000)
77+
{
78+
ms--;
79+
start += 1000;
80+
}
81+
}
7782
}
7883

7984
#include "Reset.h" // for tickReset()

0 commit comments

Comments
 (0)