我爱胆机妙音 发表于 2012-6-13 19:15:26

(求助)这段程序怎样理解?

int STD_LOOP_TIME = 9;
int lastLoopTime = STD_LOOP_TIME;
int lastLoopUsefulTime = STD_LOOP_TIME;
unsigned long loopStartTime = 0;

void loop(){

// your code ...


// *********************** loop timing control **************************
lastLoopUsefulTime = millis()-loopStartTime;
if(lastLoopUsefulTime<STD_LOOP_TIME)         delay(STD_LOOP_TIME-lastLoopUsefulTime);
lastLoopTime = millis() - loopStartTime;
loopStartTime = millis();
}这段代码第一行里的“int STD_LOOP_TIME = 9;”怎样理解?它为什么会等于9?9这个数值是怎样定出来的?
谢谢

daiqx2 发表于 2012-6-14 12:55:14

应该是程序启动后不够9毫秒就等够这个时间再执行下去。可能要等待某设备进入状态

daiqx2 发表于 2012-6-14 13:10:03

这段代码应该为了实现更准确的delay就说只delay (9)实际等待的时间会是9+执行之前代码的时间。

daiqx2 发表于 2012-6-14 13:13:08

你和别人约定十五分钟后到某地,这个9应该和这个十五一样,不过你要把路上的时间计算一下再delay
页: [1]
查看完整版本: (求助)这段程序怎样理解?