Scroll Unit
The following products are supported:
Micropython Example:
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:
class ScrollUnit
Constructors
Methods
- ScrollUnit.get_rotary_increments() int
Gets the rotation increment of the Rotary object. Can be used to determine the direction of rotation.
UIFLOW2:
- ScrollUnit.set_rotary_value(new_value: int) None
Sets the rotation value of the Rotary object.
- Parameters:
new_value (int) – adjust the current value.
UIFLOW2:
- ScrollUnit.fill_color(rgb: int) None
Set the color of the LED
- Parameters:
rgb (int) – the color of the LED, 0x000000 - 0xFFFFFF.
UIFLOW2: