I am trying to create a digitalio.DigitalInOut
object in a class in CircuitPython. The pin used is defined as a parameter in the class (pin_number
). Is there a way to do it other than with exec()
? My attempt at doing this is below, and, as you can see, it is very messy (and does not work due to problems with exec()
and classes).
exec("self.pin = digitalio.DigitalInOut(board.GP"+str(pin_number)+")", globals(), locals())
In MicroPython, I just did this:
self.pin = Pin(pin_number, Pin.OUT)
If possible, I would like to do something similar with CircuitPython, so that my main program to be compatible with either MicroPython or CircuitPython depending on which file you import from it (my main code looks something like the below).
b1 = led(pin_number=1)