def test_event_detected_not_configured_for_input(): with patch("OPi.GPIO.sysfs"): GPIO.setmode(GPIO.BOARD) GPIO.setup(23, GPIO.OUT) with pytest.raises(RuntimeError) as ex: GPIO.event_detected(23) assert str(ex.value) == "Channel 23 is configured for output"
def test_event_detected(): with patch("OPi.GPIO.sysfs"): GPIO.setmode(GPIO.BOARD) GPIO.setup(23, GPIO.IN) with patch("OPi.GPIO.event") as mock: mock.edge_detected.return_value = True assert GPIO.event_detected(23)
print('Hz1:' "{:,.0f}".format(hz)) if rpm > 10000 and rpm < 13000: GPIO.output(10, 0) GPIO.output(16, 1) elif rpm > 13000: GPIO.output(10, 1) GPIO.output(16, 0) GPIO.add_event_detect( sensor, GPIO.RISING) # execute the get_rpm function when a HIGH signal is detected try: # Loop until users quits with CTRL-C while True: if not GPIO.event_detected(sensor): GPIO.output(13, 0) rpm = 0 hz = 0 else: GPIO.output(13, 1) if not count: #GPIO.output(13,0) set_start() # create start time count = count + 1 # increase counter by 1 else: #GPIO.output(13,1) count = count + 1 if count == sample: set_end() # create end time delta = end - start # time taken to do a half rotation in seconds