Closed tmsch13 closed 2 years ago
Playing around with Timers in the microPython Simulator I found out that import machine does not import machine.Timer
import machine
machine.Timer
so:
import machine def mycallback(t): print("timer fired") timer = Timer(period=1000, mode=Timer.PERIODIC, callback=mycallback)
gives me:
Traceback (most recent call last): File "main.py", line 7, in <module> NameError: name 'Timer' isn't defined
but
from machine import Timer def mycallback(t): print("timer fired") timer = Timer(period=1000, mode=Timer.PERIODIC, callback=mycallback)
works perfectly.
I would expect importing machine would import machine.Timer to, as it also does for machine.Pin for example.
Hi @tmsch13, this is how Python works. If you just import machine, then the Timer class is available under the machine namespace, as machine.Timer.
Playing around with Timers in the microPython Simulator I found out that
import machine
does not importmachine.Timer
so:
gives me:
but
works perfectly.
I would expect importing machine would import machine.Timer to, as it also does for machine.Pin for example.