Event
Loop
案例程序
from m5stack import *
from m5ui import *
from uiflow import *
setScreenColor(0x222222)
while True:
print('Hello M5')
wait_ms(2)
功能说明
while True:
wait_ms(2)
案例程序
from m5stack import *
from m5ui import *
from uiflow import *
setScreenColor(0x222222)
def multiBtnCb_AB():
print('Button A + B Pressed')
pass
btn.multiBtnCb(btnA,btnB,multiBtnCb_AB)
def buttonA_wasPressed():
print('Button A Pressed')
pass
btnA.wasPressed(buttonA_wasPressed)
while True:
if btnB.wasPressed():
print('Button B wasPressed')
if btnC.isPressed():
print('Button C Pressed')
wait_ms(2)
功能说明
btn = btn.attach([pin])
def buttonA_wasPressed():
print('Button A Pressed')
pass
btnA.wasPressed(buttonA_wasPressed)
- 绑定按键事件回调函数, 可选事件:
- wasPressed
- wasReleased
- LongPress
- wasDoublePress
def multiBtnCb_AB():
print('Button A + B Pressed')
pass
btn.multiBtnCb(btnA,btnB,multiBtnCb_AB)
- 绑定多按键事件回调函数, 仅支持双按键组合, 同时按下按键时触发。
if btnB.wasPressed():
print('Button B wasPressed')
if btnC.isPressed():
print('Button C Pressed')
- 读取当前按键状态, 根据事件配置返回True/False, 可选事件:
- wasPressed
- wasReleased
- LongPress
- wasDoublePress
- Pressed
- Released
Software Timer
案例程序
from m5stack import *
from m5ui import *
from uiflow import *
setScreenColor(0x222222)
@timerSch.event('timer1')
def ttimer1():
print('This is a software timer!')
pass
timerSch.setTimer('timer1', 100, 0x00)
timerSch.run('timer1', 100, 0x00)
功能说明
@timerSch.event('timer1')
def ttimer1():
pass
timerSch.setTimer('timer1', 100, 0x00)
- 设置软件定时器周期,定时器模式支持以下配置:
- PERIODIC 0x00:周期循环
- ONE_SHOT 0x01:单次执行
timerSch.run('timer1', 100, 0x00)
- 开启软件定时器同时配置周期,定时器模式支持以下配置:
- PERIODIC 0x00:周期循环
- ONE_SHOT 0x01:单次执行
timerSch.stop('timer1')
Hardware Timer
案例程序
from m5stack import *
from m5ui import *
from uiflow import *
setScreenColor(0x222222)
def callback_timer3(_arg):
print('This is a hardware timer!')
pass
timerSch.timer.init(period=100, mode=timerSch.timer.PERIODIC, callback=callback_timer3)
功能说明
def callback_timer3(_arg):
pass
timerSch.timer.init(period=100, mode=timerSch.timer.PERIODIC, callback=callback_timer3)
- 配置定时器周期, 定时器模式, 以及回调函数。定时器模式支持以下配置:
- PERIODIC:周期循环
- ONE_SHOT:单次执行