Doh!!
The code should have been:
i = sensor_test_loops_out # Set the loop
counter to give the required time testing for the sensor
while i >= 0:
i = i -1
if GPIO.input(sensor_b):
time.sleep(sensor_pause_time)
else:
print ("Sensor B Activated")
break
Not the one below, which I tried to fix the original issue. With the
not in the line, the code goes round and round forever (because the line
is low). Without the not, the code breaks immediately before the sensor
has been reached.
What is the correct code to test for a high on a GPIO Pin?
Terry
On 30/04/2026 15:37, Terry Coles wrote:
i = sensor_test_loops_out # Set the loop counter
to give the required time testing for the sensor
while i >= 0:
i = i -1
if not GPIO.input(sensor_b):
time.sleep(sensor_pause_time)
else:
print ("Sensor B Activated")
break
--
Terry Coles
--
Next meeting: Online, Jitsi, Tuesday, 2026-05-05 20:00
Check to whom you are replying
Meetings, mailing list, IRC, ... https://dorset.lug.org.uk
New thread, don't hijack: mailto:[email protected]