|
请各位指导一下
我现在用millis()来量度时间,结果以毫秒为单位,代码如下
[mw_shl_code=c,true]const int buttonA = 2;
const int buttonB = 3;
int buttonStateA, buttonStateB = 0;
long startTime, endTime, duration;
void setup()
{
Serial.begin(9600);
pinMode(buttonA, INPUT);
pinMode(buttonB, INPUT);
}
void loop()
{
buttonStateA = digitalRead(buttonA);
if (buttonStateA == HIGH)
{
startTime = millis();
}
delay(100);
buttonStateB = digitalRead(buttonB);
if (buttonStateB == HIGH)
{
endTime = millis();
duration = endTime - startTime;
Serial.println(duration);
}
delay(100);
}[/mw_shl_code]
如果我想以hh:mm:ss来显示结果,是否应该加一个RTC?
这样的话,代码应该怎样写?谢谢
|
|