add:http://arduino.cc/en/Reference/Millis
[popexizhi:作为DH2321芯片的替代,delay()之后发现millis,也可以try。看来还是多看eg有好处啊:)]
----------------------------------------------
[popexizhi:作为DH2321芯片的替代,delay()之后发现millis,也可以try。看来还是多看eg有好处啊:)]
----------------------------------------------
Description
Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.
[popexizhi:50days,这个是工业级别的证明吗?还最大max的溢出值范围:)好吧log计算都忘记了,也没算出来:)]
Parameters
None
Returns
Number of milliseconds since the program started (unsigned long)
[popexizhi: unsigned long 的逻辑范围是类型取值范围: 0~4294967295 即 0~(2的32次方-1),50days是180000000毫秒左右.上面的应该是工业级别的硬件范围,4294967295换算完是3.268年左右]
Example
unsigned long time;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.print("Time: ");
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1000);
}
[popexizhi:next 在串口中调试一下]
Tip:
Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other datatypes such as ints.
-------------------------------------------------------
PS:
[popexizhi:测试8小时的Dome,调试一下硬件看看效果如何,]
-------------------------------------------------------
PS:
[popexizhi:测试8小时的Dome,调试一下硬件看看效果如何,
unsigned long time;
unsigned long oldtime=8*3600*1000;
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.print("Time: ");
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1000);
if (time> oldtime){
Serial.println("8 hours is start");
//继电器操作位置 } }
没有评论:
发表评论