You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the Board should have an attribute that is an iterable of pins, and perhaps one extra attribute for each useful restriction (like the digital pins), instead of being itself an iterable. Something like:
That would be explicit. A board.analog_pins also would help. For all pins, why not all_pins? Anyhow, I don't know whether iterating for all pins in a board would make practical sense for a Pingo user: one should know (or control) the iteration order for making use of it. They can be tuples, but probably are better as dictionaries, which allow selecting a single pin by its "key".
Perhaps it should be a class that inherits from dictionary, but that:
Iterates through its values (instead of keys), so the syntax above would work
Allow direct access to a pin by a key value, like board.digital_pins["17"]
"Multiple" key values (e.g. with __missing__), so access would work for both a default "physical" pin number and their aliases ("logical" pin names, both string and int names, etc.), without changing the "size" of the dictionaries
An iterable from all pins can be easily converted (using a list comprehension) to whatever needed (e.g. selecting all pins that are both analog and digital, selecting all power supply pins, etc.). Semantically, I don't think the board itself is a good concept for "pin iterator", but even if it is, it seems to be strangely implicit to put a restriction like "only over the digital pins". Just seen the code example for pin in my_board: do_something(pin) it's not clear whether the "pin" is digital, and it would be worse for something like for p in board: [...].
This will enable this style of programming:
for pin in my_board: do_something(pin)
However, currently I am not happy with the default of listing the Vcc and Gnd pins...
This should iterate only over the digital pins, which are the most useful for beginners.
The text was updated successfully, but these errors were encountered: