[英]How to send data to multiple raspberry pi's at a time from raspberry pi 4 via Bluetooth?
[英]How to make multiple time while loop Raspberry Pi? Python
我可以多次使用while循環嗎? 我該怎么辦呢? 例如,在此代碼中,我希望它檢測字符串“ turn left”。 如果按下,則按鈕將發送信號。 我現在的問題是如何使循環同時檢查其他字符串,例如“向右轉”,“從第一個出口離開”?
while instruction == "turn left":
if (GPIO.input(12) == False):
print("button press")
assistant.start_conversation()
break
else:
GPIO.output(3, GPIO.HIGH)
sleep(0.3)
GPIO.output(3, GPIO.LOW)
sleep(0.3)
您可以做很多事情; 例如,無限期地運行while循環,並使用“ if”比較運算符檢查指令。
while True:
if instruction == "turn left":
//do something
if instruction == "turn right":
//do something
或者,您可以使用多線程,這使您可以並行運行多個while循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.