Loops 在循环上运行的arduino代码
我在我的Arduino项目中使用了一个switch案例,在第二个案例中也使用了for循环,但是函数并没有脱离for循环。我只想运行我的第二个案例5秒,然后想打破它。帮我吧Loops 在循环上运行的arduino代码,loops,arduino,switch-statement,arduino-uno,Loops,Arduino,Switch Statement,Arduino Uno,我在我的Arduino项目中使用了一个switch案例,在第二个案例中也使用了for循环,但是函数并没有脱离for循环。我只想运行我的第二个案例5秒,然后想打破它。帮我吧 int cmd; void loop(){ // run over and over again if(Serial.available()){ Serial.println("enter 1 or 2"); cmd=Serial.read(); switc
int cmd;
void loop(){ // run over and over again
if(Serial.available()){
Serial.println("enter 1 or 2");
cmd=Serial.read();
switch (cmd){
case '1':
function1() ;
break ;
case '2':
int i=0;
for(i=0;i<100;i++){
function2();
delay(50);
}
break;
}
}
}
intcmd;
void loop(){//反复运行
if(Serial.available()){
Serial.println(“输入1或2”);
cmd=Serial.read();
开关(cmd){
案例“1”:
功能1();
打破
案例“2”:
int i=0;
对于(i=0;i您的循环将始终需要5秒以上才能完成,因为您的总延迟是5秒加上function2的执行时间。如果它没有退出循环,我打赌您的function2将对此负责。
无论如何,如果需要计时,应该使用millis()函数,结果如下:
long startTime = millis();
long delay = 50000;
while(millis() < startTime + delay){
functionw();
}
long startTime=millis();
长延时=50000;
while(毫秒()
此实现将更接近您的5秒时间限制。您的循环将始终需要5秒以上才能完成,因为您的总延迟是5秒加上function2的执行时间。如果它没有退出循环,我打赌您的function2将对此负责。
无论如何,如果需要计时,应该使用millis()函数,结果如下:
long startTime = millis();
long delay = 50000;
while(millis() < startTime + delay){
functionw();
}
long startTime=millis();
长延时=50000;
while(毫秒()
此实施将更接近您的5秒时间限制。实际上,我使用的是adafruit指纹示例文件案例1用于注册,案例2用于指纹,可在此网站上找到()并希望运行案例2,直到手指没有放在传感器上。我不确定你想完成什么,但如果你想在事情没有发生时执行X-使用中断。实际上,我使用的是adafruit指纹示例文件案例1注册,案例2指纹,可在本网站上找到()并希望运行案例2,直到手指没有放在传感器上。不确定您想要完成什么,但如果您想在未发生事件时执行X,请使用中断。