Page 1 of 1

Poor I/O pin addressing in micro:python

Posted: Wed May 19, 2021 12:58 pm
by MicroGuy
As far as I can tell, the standard MicroPython I/O control statements such as: pin6.write_digital(0) do not provide a way to change the pin number "on the fly." Thus a program cannot address a series of I/O pins in a loop as you might with:

while X < 7
pin(x).digital_write(my_list[x])
etc...

Perhaps the compiler-interpreter team could add such a capability to the next code release? Comments welcome.

Re: Poor I/O pin addressing in micro:python

Posted: Wed May 19, 2021 1:03 pm
by stijn
Create a list of pins and you're set?

Code: Select all

# CreatePin is a method creating Pin objects
pins = [CreatePin(x) for x in range(len(my_list))]
for pin, value in zip(pins, my_list):
  pin.write(value)

Re: Poor I/O pin addressing in micro:python

Posted: Tue Jun 29, 2021 1:43 pm
by rhubarbdog
What about

Code: Select all

for p in (pin0,  pin3, pin2,  pin2):
    p.write_digital(1)