Hello,
I've in the main progamm a pin initialized as output and it works. Then I did make subroutines and put this in another files for a better overview. The file I integrated wirth import. The Call of the subroutines takes place after the pin initialization.
But MicroPython shows me an error than the subroutines don't knows the pin definition. I did try continue: In the subroutines file nothing imports and nothing definitions are known.
How can I pass on the imports and definitions?
pin-init in main; no knows in subroutines?
Re: pin-init in main; no knows in subroutines?
This should work the same way it does in regular Python. The best way to solve this is to pass the pin as an argument when you call the subroutines in the other file.
main.py:
Code: Select all
import driver
p = machine.Pin(1, mode=machine.Pin.OUT)
driver.do_stuff(p)
Code: Select all
def do_stuff(p):
p.value(1)