I am writing a piece of code to control three color lamps connected to Jetson nano.
Each GPIO pin is dedicated to its color, pin, and state. Say
Pins[0] = [Color.RED, pin=11, state=State.OFF]
Pins[1] = [Color.YEL, pin=13, state=State.SOLID_ON]
Pins[2] = [Color.GRN, pin=15, state=State.BLINK]
and in SetGPIO function, I would like to command each pin like
def SetGPIO(self, color, state):
if color == Color.RED:
Pins[0].state = state
elif color == Color.YEL:
Pins[1].state = state
elif color == Color.GRN:
Pins[2].state = state
Then in Update function which called every 0.5 seconds,
def Update(self):
foreach Pin in Pins
if Pins.state == State.off:
GPIO.output(Pins.pin, GPIO.LOW)
elif Pins.state == State.SOLID_ON:
GPIO.outpu(Pins.pin, GPIO.HIGH)
elif Pins.state == State.BLINK:
toggle GPIO(Pins.pin, state)
Any suggestions on how to implement such functions in python?