Как включить датчик HC-SR04 в мой код Python.
I am building an autonomous 4WD vehicle for a project at school. I have already written the code (using Python 2) to operate it, and it takes commands through raw input. Everything works great as far as the robot itself is concerned, but now I am trying to incorporate an ultra-sonic sensor on the front of it so it will stop when it comes within 20 cm of an obstacle. The sensor is wired correctly and gives me distance feedback when using sample code I found online. The sample code gave me a function which gives me distance feedback every second and prints it out. The problem I am having is, how do I incorporate this into the code I have already written? How do I have the sensor constantly pinging for distance while also running the while loop for my robot commands? Can I use a while loop within another while loop? I am only somewhat competent with python so any help or suggestions would be greatly appreciated.
Что я уже пробовал:
Я попытался использовать цикл while в другом цикле while. Я не могу придумать, что еще можно сделать.