2024-08-01 16:26:46 +10:00
|
|
|
# test "soft" machine.Timer (no hardware ID)
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if sys.platform == "esp32":
|
|
|
|
|
print("SKIP") # TODO: Implement soft timers for esp32 port
|
|
|
|
|
raise SystemExit
|
|
|
|
|
|
2020-01-13 17:35:18 +11:00
|
|
|
|
|
|
|
|
try:
|
2022-08-18 16:57:45 +10:00
|
|
|
import time, machine as machine
|
2020-03-22 21:26:08 -05:00
|
|
|
|
2020-01-13 17:35:18 +11:00
|
|
|
machine.Timer
|
|
|
|
|
except:
|
|
|
|
|
print("SKIP")
|
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
|
|
# create and deinit
|
|
|
|
|
t = machine.Timer(freq=1)
|
|
|
|
|
t.deinit()
|
|
|
|
|
|
|
|
|
|
# deinit again
|
|
|
|
|
t.deinit()
|
|
|
|
|
|
|
|
|
|
# create 2 and deinit
|
|
|
|
|
t = machine.Timer(freq=1)
|
|
|
|
|
t2 = machine.Timer(freq=1)
|
|
|
|
|
t.deinit()
|
|
|
|
|
t2.deinit()
|
|
|
|
|
|
|
|
|
|
# create 2 and deinit in different order
|
|
|
|
|
t = machine.Timer(freq=1)
|
|
|
|
|
t2 = machine.Timer(freq=1)
|
|
|
|
|
t2.deinit()
|
|
|
|
|
t.deinit()
|
|
|
|
|
|
|
|
|
|
# create one-shot timer with callback and wait for it to print (should be just once)
|
|
|
|
|
t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t: print("one-shot"))
|
2022-08-18 16:57:45 +10:00
|
|
|
time.sleep_ms(5)
|
2020-01-13 17:35:18 +11:00
|
|
|
t.deinit()
|
|
|
|
|
|
|
|
|
|
# create periodic timer with callback and wait for it to print
|
|
|
|
|
t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t: print("periodic"))
|
2022-08-18 16:57:45 +10:00
|
|
|
time.sleep_ms(14)
|
2020-01-13 17:35:18 +11:00
|
|
|
t.deinit()
|