我有以下函数,其中有一个 for 循环。该代码在 Arduino 上运行,Serial.print
函数显示已使用正确的输入值正确输入该函数。但是没有进入 for 循环。有谁知道为什么?
void openvalveCold(int steps){
Serial.println(steps);
// Steps is confimed to be 200.
digitalWrite(sleep1,HIGH);
for (antalsteg = 0; antalsteg == steps; antalsteg++)
{
Serial.println("2");
//digitalWrite(dir1,HIGH);
digitalWrite(stepp1,HIGH);
delay(25);
digitalWrite(stepp1,LOW);
delay(25);
Serial.println(antalsteg);
nr_of_steps_cold++;
}
}
void loop{
// calling on function
openvalveCold(200);
}
最佳答案
for 循环通常是这样构造的:
for(init counter; condition; increase counter)
您做出了(错误的)假设,即循环直到条件为真。那是错误的。它循环而它是真的。更改为:
for (antalsteg = 0; antalsteg < steps; antalsteg++)
关于c++ - 即使初始要求为真,也不会进入 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56030337/