Hi mbell,
this answer will only be a part of your solution, but may help you.
I have dynamical declared my output pins with a class.
Code: Select all
from machine import Pin, Timer
import time
my_OUT = [] # this will contain all dynamic declared output objects
my_output_pins = [0, 1, 6, 7, 8, 9] # these are my Pi Pico pins i connected a led to
class my_output(): #here starts the class for all output pins
def __init__(self, id, pin): # this function will create a output object
self.id = id #not mandatory needed but can be helpful later in more complex context
self.out_pin = Pin(pin, Pin.OUT) # configure the output pin as output ;-)
self.out_pin.off() # the pin starts LOW
def state(self, state): # function to manipulate the pinstate
if state == 0:
self.out_pin.off()
if state == 1:
self.out_pin.on()
if state == 2:
self.out_pin.toggle()
for idx, pin in enumerate(my_output_pins): # for loop to create the output objects and put them in the list my_OUT to make them accessable and iterable
my_OUT.append(my_output(idx, pin))
while True:
my_OUT[2].state(2) # this accesses the third object (0, 1, 2, ... ) (which means GP06 in this case) in the objects list and goes to the state function in the class. The parameter 2 makes the output toggling every 250 ms
time.sleep_ms(250)
With this solution, you can have "unlimited" objects declared as a ouput and acces every objects state very easy.
I hope this helps you a bit.