Hi,

At WMT, I've been having some issues checking  the state of a GPIO pin, which is used to detect the presence of a train.  However, I suspect that what I am trying to do in Python is wrong.  The Sensor output is low when there is no train in front of it and rises when there is.

Here is what I've been using:

        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

Where sensor_b is the GPIO Pin Number of the first Sensor encountered on the outward leg.  This is performed repeatedly in a loop so sensor_pause_time determines how long to wait before testing again.

I suspect that my test in the first line is too simplistic, but I thought that I had done this before.

--
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]

Reply via email to