Scroll Unit

支持以下产品:

滚动

MicroPython 应用示例

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import *
 9from unit import ScrollUnit
10
11
12label0 = None
13label1 = None
14label2 = None
15label3 = None
16i2c0 = None
17scroll_0 = None
18
19
20def setup():
21    global label0, label1, label2, label3, i2c0, scroll_0
22
23    M5.begin()
24    Widgets.fillScreen(0x222222)
25    label0 = Widgets.Label("label0", 73, 75, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu56)
26    label1 = Widgets.Label("label1", 135, 138, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu12)
27    label2 = Widgets.Label("label2", 9, 9, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
28    label3 = Widgets.Label("label3", 10, 31, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
29
30    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
31    scroll_0 = ScrollUnit(i2c0, 0x40)
32    label2.setText(str((str("bootloader ver: ") + str((scroll_0.get_bootloader_version())))))
33    label3.setText(str((str("firmware ver: ") + str((scroll_0.get_firmware_version())))))
34    scroll_0.set_rotary_value(100)
35
36
37def loop():
38    global label0, label1, label2, label3, i2c0, scroll_0
39    M5.update()
40    if scroll_0.get_rotary_status():
41        label0.setText(str(scroll_0.get_rotary_value()))
42        label1.setText(str(scroll_0.get_rotary_increments()))
43    if scroll_0.get_button_status():
44        scroll_0.reset_rotary_value()
45        scroll_0.fill_color(0x33CC00)
46    else:
47        scroll_0.fill_color(0xFF0000)
48
49
50if __name__ == "__main__":
51    try:
52        setup()
53        while True:
54            loop()
55    except (Exception, KeyboardInterrupt) as e:
56        try:
57            from utility import print_error_msg
58
59            print_error_msg(e)
60        except ImportError:
61            print("please update to latest firmware")

UiFlow2 应用示例

example.png

cores3_scroll_example.m5f2

class ScrollUnit

Constructors

class ScrollUnit(i2c, address: int | list | tuple = 0x40)

创建一个 Rotary 对象。

参数:
  • i2c – I2C 对象。

  • address – I2C 地址,默认为 0x40。

UIFLOW2:

init.png

Methods

ScrollUnit.get_rotary_status() bool

获取 Rotary 对象的旋转状态。

UIFLOW2:

get_rotary_status.png

ScrollUnit.get_rotary_value() int

获取 Rotary 对象的旋转值。

UIFLOW2:

get_rotary_value.png

ScrollUnit.get_rotary_increments() int

获取 Rotary 对象的旋转增量。可用于判断旋转方向。

UIFLOW2:

get_rotary_increments.png

ScrollUnit.reset_rotary_value() None

重置 Rotary 对象的旋转值。

UIFLOW2:

reset_rotary_value.png

ScrollUnit.set_rotary_value(new_value: int) None

设置 Rotary 对象的旋转值。

参数:

new_value (int) – 调整当前值。

UIFLOW2:

set_rotary_value.png

ScrollUnit.get_button_status() bool

获取旋转编码器按键的当前状态。

UIFLOW2:

get_button_status.png

ScrollUnit.fill_color(rgb: int) None

设置 LED 的颜色

参数:

rgb (int) – LED 的颜色,范围为 0x000000 - 0xFFFFFF。

UIFLOW2:

fill_color.png

ScrollUnit.get_bootloader_version() str

获取引导加载程序版本。

返回:

bootloader 版本

UIFLOW2:

get_bootloader_version.png

ScrollUnit.get_firmware_version() str

获取固件版本。

返回:

固件版本

UIFLOW2:

get_firmware_version.png