作者:mobiledu2502862777 | 来源:互联网 | 2023-02-01 22:44
我无法让这个循环只运行一次.我有一个标志设置,我的理解是它将运行一次,更改flag = 1
,然后不再运行但是当我执行它时,循环会一遍又一遍地运行.任何帮助表示赞赏.
编辑:我发现的问题是即使我的电压满足if语句,循环仍继续运行.
voltage = analogRead(A0); //reads in voltage from pin A0
Serial.println(voltage);
//Calibration routine
do {
if ((voltage >= 1) && (voltage <= 10)) {
//while the voltage is between 4.88 and 48.8 mV the calibration light will flash once
//this ensures the voltage is above 0 and lower than the threshold for the max voltage routine
digitalWrite(calibrationLED, HIGH);
delay(2000);
digitalWrite(calibrationLED, LOW);
delay(1000);
digitalWrite(calibrationLED, HIGH);
delay(2000);
Serial.println("Calibrated");
delay(5000);
voltageInitial = analogRead(A0);
//stores the initial voltage to a separate variable, does not change over the course of the crimp
Serial.println("Initial Voltage: ");
Serial.println(voltageInitial);
flag = 1;
}
} while (flag == 0);
dbush..
5
该flag
变量将只得到设置为1,如果if
条件为真.当voltage
值为1到10 时会发生这种情况.
如果值voltage
不在1 - 10范围内,flag
则不会设置.并且由于voltage
从未在循环内部进行修改,因此您将拥有无限循环.
1> dbush..:
该flag
变量将只得到设置为1,如果if
条件为真.当voltage
值为1到10 时会发生这种情况.
如果值voltage
不在1 - 10范围内,flag
则不会设置.并且由于voltage
从未在循环内部进行修改,因此您将拥有无限循环.