Skip to content
Discussion options

You must be logged in to vote

If I don't put global pin32 at the top of def main(): I get the error: Traceback (most recent call last): File "main.py", line 33, in <module> File "main.py", line 20, in main (line in question) NameError: local variable referenced before assignment It appears that doing pin32.on() is OK but not OK if trying to change any of its parameters.

pin32 = Pin(32, Pin.OUT, hold=False) does not merely change a parameter of pin32. For python, this creates a new instance of a Pin object with the new parameters, even when this is only a reference to the already-existing Pin object (due to the most-likely singleton characteristic of Pin objects).
After that, the old (maybe global) pin32 instance is…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@sosi-deadeye
Comment options

@karfas
Comment options

@davefes
Comment options

@bixb922
Comment options

@davefes
Comment options

Answer selected by davefes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants