Python Forum
need help with ultrasonic sensor code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with ultrasonic sensor code
#4
Maybe something like this...using a control flag (run_script) to avoid multiple calls of test.sh.

def main():

    try:
        run_script = True
        while True:
            Ergebnis = MesseDistanz()
            print("Gemessene Entfernung: %.1f cm (Signallaufzeit: %.4fms)" % (Ergebnis[0], Ergebnis[1]))
            if Ergebnis[0] < 10 and run_script:
                os.system('/home/pi/test.sh')
                run_script = False
            if Ergebnis[0] >= 10:
                run_script = True
            time.sleep(1)

    except KeyboardInterrupt:
        print("Messung abgebrochen")
        GPIO.cleanup()
Reply


Messages In This Thread
need help with ultrasonic sensor code - by mpmm366 - Jun-28-2018, 01:34 PM
RE: need help with ultrasonic sensor code - by gontajones - Jun-28-2018, 02:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sensor code that starts heater chano 3 3,187 Jun-05-2019, 10:54 AM
Last Post: michalmonday
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 2,220 Nov-29-2018, 12:44 PM
Last Post: jenkins43
  RPi with IR Sensor pimlicosnail 1 2,223 Jun-24-2018, 08:53 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020