从这一篇开始, 我们按模块一个个看QuecPython相关内容, 虽然大家都很期待4G,IOT相关的模块, 但我们还是要从基础的machine模块开始
一. machine.Pin
详见上一篇GPIO部分 : https://www.jianshu.com/p/57e38295105a
二. machine.UART
详见上一篇UART部分
三. machine.Timer 硬件定时器
EC600s有硬件定时器0-3, 使用定时器时需注意:定时器0-3,每个在同一时间内只能执行一件任务,且多个对象不可使用同一个定时器。
1. 创建Timer对象
from machine import Timer
timer1 = Timer(Timer.Timer1)
2. 启动定时器
timer.start(period, mode, callback)
参数:
这里要注意, 传参要传关键字参数, 位置参数并不能正常运行,
此外, 回调函数有默认隐式参数args, callback里要建立形参args接收,否则报错

返回值
启动成功返回整型值0,失败返回整型值-1。
3. 关闭定时器
timer.stop()
参数:
无返回值
启动成功返回整型值0,失败返回整型值-1。
4. 举例: 倒计时
from machine import Timer
count = 20
def timer0_callback(args):
global count
count -=1
print("默认传参:",args)
print(count)
if count <=0:
timer0.stop