Poor I/O pin addressing in micro:python

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
MicroGuy
Posts: 17
Joined: Sun Jan 17, 2021 8:31 pm

Poor I/O pin addressing in micro:python

Post by MicroGuy » Wed May 19, 2021 12:58 pm

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.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

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

Post by stijn » Wed May 19, 2021 1:03 pm

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)

rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

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

Post by rhubarbdog » Tue Jun 29, 2021 1:43 pm

What about

Code: Select all

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

Post Reply