CardKB Unit

Support the following products:

CardKB Unit

CardKB Unit v1.1

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 unit import CardKBUnit
 9from hardware import *
10
11
12label0 = None
13i2c0 = None
14cardkb_0 = None
15
16
17def cardkb_0_pressed_event(kb):
18    global label0, i2c0, cardkb_0
19    label0.setText(str(cardkb_0.get_string()))
20
21
22def setup():
23    global label0, i2c0, cardkb_0
24
25    M5.begin()
26    Widgets.fillScreen(0x222222)
27    label0 = Widgets.Label("label0", 132, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
28
29    i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
30    cardkb_0 = CardKBUnit(i2c0)
31    cardkb_0.set_callback(cardkb_0_pressed_event)
32
33
34def loop():
35    global label0, i2c0, cardkb_0
36    M5.update()
37    cardkb_0.tick()
38
39
40if __name__ == "__main__":
41    try:
42        setup()
43        while True:
44            loop()
45    except (Exception, KeyboardInterrupt) as e:
46        try:
47            from utility import print_error_msg
48
49            print_error_msg(e)
50        except ImportError:
51            print("please update to latest firmware")

UIFLOW2 Example:

example.png

cores3_cardkb_example.m5f2

class CardKBUnit

Constructors

class CardKBUnit(i2c: I2C, address: int | list | tuple = 0x5F)

Create a CardKBUnit object.

参数:
  • i2c – I2C object

  • address – I2C address, 0x5F by default

UIFLOW2:

init.png

Methods

CardKBUnit.get_key() int

Read the key value.

返回:

key value, int

UIFLOW2:

get_key.png

CardKBUnit.get_string() str

Read the key string.

返回:

key string, str

UIFLOW2:

get_string.png

CardKBUnit.is_pressed() bool

Check if the key is pressed.

返回:

True if the key is pressed, False otherwise

UIFLOW2:

is_pressed.png

CardKBUnit.set_callback(handler)

Set the key press event callback.

参数:

handler – callback function

UIFLOW2:

pressed_event.png

Example:

from cardkb_unit import CardKBUnit

def cb(key):
    print(key)

cardkb = CardKBUnit(i2c)
cardkb.set_callback(cb)
while True:
    cardkb.tick()
CardKBUnit.tick()

Update the key status.

UIFLOW2:

tick.png