diff --git a/Scripts/GpioManager.py b/Scripts/GpioManager.py index a6eca57..e996766 100644 --- a/Scripts/GpioManager.py +++ b/Scripts/GpioManager.py @@ -8,7 +8,7 @@ class GpioManager: def __init__(self): if RPI_ENV: print("Running on Raspberry Pi environment.") - GPIO.setmode(GPIO.BCM) + GPIO.setmode(GPIO.BOARD) else: print("Running in a non-Raspberry Pi environment. GPIO operations will be simulated.") self.state = {} diff --git a/Scripts/Main.py b/Scripts/Main.py index 3f940ce..3cda63f 100644 --- a/Scripts/Main.py +++ b/Scripts/Main.py @@ -20,25 +20,28 @@ def cleanupGpio(gpio:GpioManager): def readDistance(gpio:GpioManager, trig, echo): + # Ensure trigger is low gpio.output(trig, False) time.sleep(0.05) + + # Send a 10us pulse to trigger gpio.output(trig, True) time.sleep(0.00001) gpio.output(trig, False) - pulseStart = None - pulseEnd = None - timeout = time.time() + 1 + # Wait for the echo pin to go high + startTime = time.monotonic() while gpio.input(echo) == 0: - pulseStart = time.time() - if time.time() > timeout: - return -1 + if time.monotonic() - startTime > 1: + return -1 # Timeout waiting for echo to start + pulseStart = time.monotonic() + + # Wait for the echo pin to go low while gpio.input(echo) == 1: - pulseEnd = time.time() - if time.time() > timeout: - return -1 - if pulseStart is None or pulseEnd is None: - return -1 + if time.monotonic() - pulseStart > 1: + return -1 # Timeout waiting for echo to end + pulseEnd = time.monotonic() + pulseDuration = pulseEnd - pulseStart distance = pulseDuration * 17150 distance = round(distance, 2) diff --git a/Scripts/PinDescription.py b/Scripts/PinDescription.py index 2065459..7cba24a 100644 --- a/Scripts/PinDescription.py +++ b/Scripts/PinDescription.py @@ -1,3 +1,3 @@ -MOTOR_PIN = 17 -ULTRASONIC_TRIG = 23 -ULTRASONIC_ECHO = 24 +MOTOR_PIN = 32 +ULTRASONIC_TRIG = 40 +ULTRASONIC_ECHO = 38 diff --git a/config.yaml b/config.yaml index c22bce4..4060a36 100644 --- a/config.yaml +++ b/config.yaml @@ -1,2 +1,2 @@ -appVersion: 1.0.1.1001 +appVersion: 1.1.0.1002