这是代码:
def check_ultra():
global arduinoSerialData, y, i, x
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 "c" in myData:
myData = myData.replace("c", str(0))
if y == 1:
y = 3
if float(myData) > 15:
x = 0
return y, x
else:
if float(myData) < 15 and float(myData) > 1:
y = 1
x = 0
return y, x
elif "a" in myData:
myData = myData.replace("a", str(0))
if y == 2:
y = 3
if float(myData) > 15:
x = 0
return y, x
else:
if float(myData) < 15 and float(myData) > 1:
y = 2
x = 0
return y, x
else:
y = 0
return y
set_servo1_angle(0)
set_servo2_angle(90)
go_out_count = 0
m1 = 0
count = 3
y = 0
i = 0
x = 0
while y == None or y == 0 or x == 1:
# i = 0
# y = None
check_ultra()
if y == 1 and x == 0:
print("1")
sleep(2)
elif y == 2 and x == 0:
print('2')
sleep(2)
这当前所做的是每次传感器 1 被阻塞时打印 1 ,但随后它会结束代码。我想让它每次我阻塞一个传感器时,它都会打印相应的打印语句,无论我阻塞传感器多少次。我尝试添加许多变量来提供帮助,但它们没有用。如何使循环不断重复?