I’m trying to write a program that will loop through 3 GPIO pins connected to an external charging pad and see if a device has been placed on the pad (high voltage). If high signal is detected the program will stop at that pin. Is there a way to wait indefinitely at a pin using the time library? How would I go about continuously checking the 3 pins? I have written some starter python code to try to figure this out which I will provide.
class switch(object): def __init__(self, value): self.value = value self.fall = False def __iter__(self): """Return the match method once, then stop""" yield self.match raise StopIteration def match(self, *args): """Indicate whether or not to enter a case suite""" if self.fall or not args: return True elif self.value in args: # changed for v1.5, see below self.fall = True return True else: return False PAD1 = 17 PAD2 = 27 PAD3 = 22 for case in switch(PAD1) if case(GPIO.output(17, true)) wait break for case in switch(PAD2) if case(GPIO.output(26, true)) wait break for case in switch(PAD3) if case(GPIO.output(22, true)) wait break
In using the switch class I am trying to get the program to switch from pin to pin. Wondering if this is sound logic to follow to achieve this.