Limit Unit

Unit Limit 是一种行程开关单元,当开关手柄在外力作用下闭合时,会将数字信号接口从 3.3V 高电平拉低到 0V 低电平,从而向 MCU 或其他主控外设提供限位触发信号。它适用于各种运动机械和设备,用于控制其行程并进行终端限位保护。

支持以下产品:

LimitUnit

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 unit import LIMITUnit
 9
10
11title0 = None
12label1 = None
13label0 = None
14limit_0 = None
15
16
17def setup():
18    global title0, label1, label0, limit_0
19
20    M5.begin()
21    Widgets.fillScreen(0x222222)
22    title0 = Widgets.Title(
23        "LimitUnit Core2 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18
24    )
25    label1 = Widgets.Label(
26        "Button State:", 395, 150, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
27    )
28    label0 = Widgets.Label(
29        "Limit Counter Value:", 1, 102, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
30    )
31
32    limit_0 = LIMITUnit((33, 32), True, type=2)
33    limit_0.count_reset()
34
35
36def loop():
37    global title0, label1, label0, limit_0
38    M5.update()
39    label0.setText(str((str("Limit Counter Value:") + str((limit_0.count_value)))))
40
41
42if __name__ == "__main__":
43    try:
44        setup()
45        while True:
46            loop()
47    except (Exception, KeyboardInterrupt) as e:
48        try:
49            from utility import print_error_msg
50
51            print_error_msg(e)
52        except ImportError:
53            print("please update to latest firmware")

UiFlow2 应用示例:

example.png

limit_core2_example.m5f2

class LimitUnit

Constructors

class LimitUnit(pin_num, active_low, pullup_active)

使用指定的引脚、低电平有效配置和上拉电阻状态初始化一个 Limit 实例。

参数:
  • pin_num – 连接到限位器的 GPIO 引脚编号。

  • active_low (bool) – 用于确定限位信号是否为低电平有效。默认值为 True。

  • pullup_active (bool) – 指定是否启用内部上拉电阻。默认值为 True。

UIFLOW2:

init.png

Methods

LimitUnit.count_reset()

将计数值重置为 0。

UIFLOW2:

count_reset.png

LimitUnit.isHolding()

检查当前是否正在保持限制。

UIFLOW2:

isHolding.png

LimitUnit.setCallback(type, cb)

为指定的限位事件类型设置回调函数。

参数:
  • type – 事件类型(例如 WAS_CLICKED、WAS_DOUBLECLICKED)。

  • cb – 用于该事件执行的回调函数。

UIFLOW2:

setCallback.png

LimitUnit.tick(pin)

根据限位开关的引脚状态监控其状态转换,并触发相应的处理函数。

UIFLOW2:

tick.png