mirror of
https://github.com/m5stack/M5Cloud.git
synced 2026-05-20 10:07:21 -07:00
22 lines
460 B
Python
22 lines
460 B
Python
|
|
# https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/timer
|
||
|
|
|
||
|
|
import machine
|
||
|
|
|
||
|
|
tcounter = 0
|
||
|
|
|
||
|
|
p1 = machine.Pin(27)
|
||
|
|
p1.init(p1.OUT)
|
||
|
|
p1.value(1)
|
||
|
|
|
||
|
|
def tcb(timer):
|
||
|
|
global tcounter
|
||
|
|
if tcounter & 1:
|
||
|
|
p1.value(0)
|
||
|
|
else:
|
||
|
|
p1.value(1)
|
||
|
|
tcounter += 1
|
||
|
|
if (tcounter % 10000) == 0:
|
||
|
|
print("[tcb] timer: {} counter: {}".format(timer.timernum(), tcounter))
|
||
|
|
|
||
|
|
t1 = machine.Timer(2)
|
||
|
|
t1.init(period=20, mode=t1.PERIODIC, callback=tcb)
|