这是我的代码和我,我试图在计时器上运行.......,当我的数字写入4出现时,它会在大于2.5v且我的程序继续运行时关闭。 ...但是,我试图把它放入定时器,如果它没有,在5分钟内达到2.5V的阈值,它将关闭我的数字写入4关闭和另一个数字写入6关闭
if (analogValue < threshold2){ //less 2volts
digitalWrite(4,HIGH) ; //compressor on
}
if (analogValue > threshold3){ //greater than 2.5 volts
digitalWrite(4,LOW) ; // compressor off
}
答案 0 :(得分:0)
创建一个unsigned long,它将存储一个定时值“startMillis”并使用这段代码。
//drops below threshold
if (analogValue < threshold2){
//turn compressor on and start timing value
digitalWrite(4,HIGH) ;
startMillis = millis();
//the block below will break if either the
//voltage goes over the threshold or if
//the timer variable is greater than
//300,000ms (5min)
//additionally, if the timer is tripped it will
//stop channel 6 before breaking
while ( analogValue < threshold3 ) {
if ( millis() - startMillis > 300000 ) {
digitalWrite(6,LOW) ;
break;
}
}
//after either condition breaks but before
//exiting the if() code
digitalWrite(4,LOW) ;
}