Arduino millis() - millis() 怎么能等于 0 以外的任何东西?

How can Arduino millis() - millis() equal anything other than 0?

本文关键字:millis 任何东 怎么能 Arduino      更新时间:2023-10-16

所以我知道millis((返回自程序开始运行以来经过的时间,对吧?

现在我遇到了在这样的延迟中使用millis((的情况:

long dly = millis();
while (millis() - dly < 250) {
yield();        // enough time to send response
}

millis() - dly的值怎么能大于 0? 如果重点是无限期地屈服,为什么有人会使用这样的延迟?

我不是 ardunio 程序员,但看看代码:

long dly = millis();
while (millis() - dly < 250) {
yield();        // enough time to send response
}

在第 1 行,您定义一个变量,该变量保存自开始以来经过的时间,然后在 while 循环中检索当前的 millis((,直到它大于 250ms。

例:

long dly = millis(); => Say millis = 1250,
inside while loop => millis will update itself until its 1500

本质上,代码等待 250 毫秒。每次循环运行时,它都会返回当前的毫秒,你的假设是它将返回旧值。

相关文章: