0

这是代码:

def check_ultra():
    global arduinoSerialData,y,i
    y=None
    i=None
    while True:
        if arduinoSerialData.inWaiting() > 1:
            myData = arduinoSerialData.readline()
            myData = str(myData)
            myData = myData.replace("b'", '')
            myData = myData.replace("\\r\\n'", str(0))
            myData = myData.replace("\\r00.000", str(0))
            myData = myData.replace("\\r00.000", str(0))
            if myData.find("b"):
                myData_b = myData.replace("a", str(0))
                if float(myData_b) < 15 and float(myData_b) > 1:
                    y=1
                    return y
            if myData.find("a"):
                myData_a = myData.replace("b", str(0))
                if float(myData_a) < 15 and float(myData_a) > 1:
                    y=2
                    i=1
                    return i
                    return y
            else:
                y=0
                return y


m1=0
count=1
y=0
i=0
y == 0
while y==None or y==0:
    i=0
    y=None
    check_ultra()
    while y==2 and i==1:
        y=None
        i=None
        print("Hello")
        break

问题出在 y==2 循环上。由于某种原因,它不断重复自己,即使 y=None。任何人都知道如何解决这个问题,我整天都在研究它。谢谢!

4

1 回答 1

0

缩进错误。将 break 放在循环内。

例如:

for val in "string":
    if val == "i":
        break
    print(val)
于 2020-08-09T10:50:49.847 回答