- 加载基本库
from m5stack import *
from m5ui import *
from uiflow import *
- 清除屏幕
lcd.clear()
- 设置屏幕亮度
axp.setLcdBrightness(30)
- 填充屏幕
setScreenColor(0x111111)
- 设置屏幕旋转角度
lcd.setRotation(1)
- 打印文本
lcd.print('Hello World', 30, 50, 0xffffff)
- 蜂窝喇叭控制
# 发出1800频率蜂鸣持续200毫秒
speaker.tone(1800, 200)
# 设置音量
speaker.setVolume(1)
- LED控制
M5Led.on()
M5Led.off()
- 获取电量
axp.getBatVoltage()
- 关闭电源
axp.powerOff()
- wifi控制
import wifiCfg
# 连接wifi
wifiCfg.doConnect('ssid', 'password')
# 断开wifi
wifiCfg.disconnect()
- RTC时钟
# 设置rtc时间
rtc.setTime(2022, 4, 28, 10, 10, 10)
# 获取rtc时间
rtc.now()
- 时间等待
import time
# 毫秒
wait_ms(1)
# 秒
wait(1)
- NTP服务
import ntptime
# 连接ntp服务器
ntp = ntptime.client(host='cn.pool.ntp.org', timezone=8)
# 获取日期
ntp.formatDate('-')
# 获取时间
ntp.formatTime(':')
- 陀螺仪
import imu
imu0 = imu.IMU()
# 获取翻滚角数值
imu0.ypr[1]
# 获取俯仰角数值
imu0.ypr[2]
# 获取X轴加速度
imu0.acceleration[0]
# 获取Y轴加速度
imu0.acceleration[1]
# 获取Z轴加速度
imu0.acceleration[2]
# 获取X轴角速度
imu0.gyro[0]
# 获取Y轴角速度
imu0.gyro[1]
# 获取Z轴角速度
imu0.gyro[2]
- 设置字体
lcd.font(lcd.FONT_Default)
lcd.font(lcd.FONT_DefaultSmall)
lcd.font(lcd.FONT_DejaVu18)
lcd.font(lcd.FONT_DejaVu24)
lcd.font(lcd.FONT_DejaVu40)
lcd.font(lcd.FONT_DejaVu56)
lcd.font(lcd.FONT_DejaVu72)
lcd.font(lcd.FONT_Ubuntu)
lcd.font(lcd.FONT_Comic)
# 中文字体
lcd.font(lcd.FONT_UNICODE)
- 按钮事件
# 点击判断
btnA.isPressed()
def buttonA_wasPressed():
pass
# 回调函数
btnA.wasPressed(buttonA_wasPressed)
- 绘制二维码
lcd.qrcode('hello world', x=0, y=0, width=135, version=6)