RELAY Unit

支持以下产品:

RELAY

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 RelayUnit
 9import time
10
11
12relay_0 = None
13
14
15def setup():
16    global relay_0
17
18    M5.begin()
19    Widgets.fillScreen(0x222222)
20
21    relay_0 = RelayUnit((36, 26))
22    print(relay_0.get_status())
23    relay_0.on()
24    time.sleep(1)
25    relay_0.off()
26    time.sleep(1)
27    relay_0.set_status(True)
28    time.sleep(1)
29
30
31def loop():
32    global relay_0
33    M5.update()
34
35
36if __name__ == "__main__":
37    try:
38        setup()
39        while True:
40            loop()
41    except (Exception, KeyboardInterrupt) as e:
42        try:
43            from utility import print_error_msg
44
45            print_error_msg(e)
46        except ImportError:
47            print("please update to latest firmware")

UIFLOW2 Example:

example.png

relay_core_example.m5f2

class RelayUnit

Constructors

class RelayUnit(io)

创建一个RelayUnit对象.

参数如下:
  • io 定义控制引脚。

UIFLOW2:

init.png

Methods

RelayUnit.get_status()

获取继电器开关状态。

UIFLOW2:

get_status.png

RealyUnit.on()

闭合继电器。

UIFLOW2:

on.png

RealyUnit.off()

打开继电器。

UIFLOW2:

off.png

RealyUnit.set_status()

设置继电器状态( True 或者 false )。

UIFLOW2:

set_status.png