matheusbrat
Member
Hello Paul,
Delay(0) puts Teensy in a infinite loop;
If you replace delay(1) to delay(0) the Teensy freeze
From pins_teensy.c
You can see that ms-- will trigger then ms will have the value -1 and that will keep going. I don't think this should be the correct behavior. Maybe an if on the begin is a solution? Anyway, delay(0) doesn't make sense I know, it is just a suggestion, otherwise I think it should be well documented that delay receives values starting at 1.
Delay(0) puts Teensy in a infinite loop;
Code:
void setup() {
delay(5000);
Serial.begin(57600);
Serial.println("oI");
}
void loop() {
Serial.println("AAA");
delay(1);
}
If you replace delay(1) to delay(0) the Teensy freeze
From pins_teensy.c
Code:
void delay(uint32_t ms)
{
uint32_t start = micros();
while (1) {
if ((micros() - start) >= 1000) {
ms--;
if (ms == 0) break;
start += 1000;
}
yield();
}
}
You can see that ms-- will trigger then ms will have the value -1 and that will keep going. I don't think this should be the correct behavior. Maybe an if on the begin is a solution? Anyway, delay(0) doesn't make sense I know, it is just a suggestion, otherwise I think it should be well documented that delay receives values starting at 1.
Code:
void delay(uint32_t ms)
{
if (ms == 0)
break;
uint32_t start = micros();
while (1) {
if ((micros() - start) >= 1000) {
ms--;
if (ms == 0) break;
start += 1000;
}
yield();
}
}
}