1# test machine.Timer
2
3try:
4    import utime, umachine as machine
5
6    machine.Timer
7except:
8    print("SKIP")
9    raise SystemExit
10
11# create and deinit
12t = machine.Timer(freq=1)
13t.deinit()
14
15# deinit again
16t.deinit()
17
18# create 2 and deinit
19t = machine.Timer(freq=1)
20t2 = machine.Timer(freq=1)
21t.deinit()
22t2.deinit()
23
24# create 2 and deinit in different order
25t = machine.Timer(freq=1)
26t2 = machine.Timer(freq=1)
27t2.deinit()
28t.deinit()
29
30# create one-shot timer with callback and wait for it to print (should be just once)
31t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t: print("one-shot"))
32utime.sleep_ms(5)
33t.deinit()
34
35# create periodic timer with callback and wait for it to print
36t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t: print("periodic"))
37utime.sleep_ms(14)
38t.deinit()
39