Skip to content

Commit 2c58eab

Browse files
committed
Add relay unit
1 parent 733651c commit 2c58eab

File tree

6 files changed

+254
-0
lines changed

6 files changed

+254
-0
lines changed

docs/en/refs/unit.relay.ref

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. |RELAY| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/relay/relay_01.webp
2+
:target: https://docs.m5stack.com/en/unit/relay
3+
:height: 200px
4+
:width: 200 px
5+
6+
7+
.. |example.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/example.svg
8+
9+
.. |init.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/init.svg
10+
11+
.. |get_status.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/get_status.svg
12+
13+
.. |on.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/on.svg
14+
15+
.. |off.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/off.svg
16+
17+
.. |set_status.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/set_status.svg
18+
19+
20+
21+
.. |relay_core_example.m5f2| raw:: html
22+
23+
<a href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/m5f2_examples/unit/relay/relay_core_example.m5f2" target="_blank">relay_core_example.m5f2</a>
24+

docs/en/units/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Unit
1616
ultrasonic.rst
1717
pir.rst
1818
ncir.rst
19+
relay.rst

docs/en/units/relay.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
RELAY Unit
2+
==================
3+
4+
.. include:: ../refs/unit.relay.ref
5+
6+
Support the following products:
7+
8+
9+
|RELAY|
10+
11+
12+
Micropython Example::
13+
14+
import os, sys, io
15+
import M5
16+
from M5 import *
17+
import time
18+
from unit import *
19+
20+
relay_0 = None
21+
22+
def setup():
23+
global relay_0
24+
25+
relay_0 = RelayUnit((8,9))
26+
M5.begin()
27+
Widgets.fillScreen(0x222222)
28+
29+
print(relay_0.get_status())
30+
relay_0.on()
31+
time.sleep(1)
32+
relay_0.off()
33+
time.sleep(1)
34+
relay_0.set_status(True)
35+
time.sleep(1)
36+
37+
38+
39+
UIFLOW2 Example:
40+
41+
|example.svg|
42+
43+
.. only:: builder_html
44+
45+
|relay_core_example.m5f2|
46+
47+
class RelayUnit
48+
-----------------
49+
50+
Constructors
51+
--------------
52+
53+
.. class:: RelayUnit(io)
54+
55+
Create a RelayUnit object.
56+
57+
The parameters is:
58+
- ``io`` Define the control pin.
59+
60+
61+
UIFLOW2:
62+
63+
|init.svg|
64+
65+
66+
Methods
67+
-------
68+
69+
.. method:: RelayUnit.get_status()
70+
71+
72+
Gets the relay switch status.
73+
74+
UIFLOW2:
75+
76+
|get_status.svg|
77+
78+
.. method:: RealyUnit.on()
79+
80+
turn on the relay.
81+
82+
UIFLOW2:
83+
84+
|on.svg|
85+
86+
.. method:: RealyUnit.off()
87+
88+
Turn off the relay.
89+
90+
UIFLOW2:
91+
92+
|off.svg|
93+
94+
.. method:: RealyUnit.set_status()
95+
96+
Set the relay status (True or false).
97+
98+
UIFLOW2:
99+
100+
|set_status.svg|
101+
102+

docs/zh_CN/refs/unit.relay.ref

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. |RELAY| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/relay/relay_01.webp
2+
:target: https://docs.m5stack.com/zh_CN/unit/relay
3+
:height: 200px
4+
:width: 200 px
5+
6+
7+
.. |example.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/example.svg
8+
9+
.. |init.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/init.svg
10+
11+
.. |get_status.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/get_status.svg
12+
13+
.. |on.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/on.svg
14+
15+
.. |off.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/off.svg
16+
17+
.. |set_status.svg| image:: https://static-cdn.m5stack.com/mpy_docs/unit/relay/set_status.svg
18+
19+
20+
21+
.. |relay_core_example.m5f2| raw:: html
22+
23+
<a href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/m5f2_examples/unit/relay/relay_core_example.m5f2" target="_blank">relay_core_example.m5f2</a>
24+

docs/zh_CN/unit/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Unit
1616
ultrasonic.rst
1717
pir.rst
1818
ncir.rst
19+
relay.rst

docs/zh_CN/unit/relay.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
RELAY Unit
2+
==================
3+
4+
.. include:: ../refs/unit.relay.ref
5+
6+
支持以下产品:
7+
8+
9+
|RELAY|
10+
11+
12+
Micropython Example::
13+
14+
import os, sys, io
15+
import M5
16+
from M5 import *
17+
import time
18+
from unit import *
19+
20+
relay_0 = None
21+
22+
def setup():
23+
global relay_0
24+
25+
relay_0 = RelayUnit((8,9))
26+
M5.begin()
27+
Widgets.fillScreen(0x222222)
28+
29+
print(relay_0.get_status())
30+
relay_0.on()
31+
time.sleep(1)
32+
relay_0.off()
33+
time.sleep(1)
34+
relay_0.set_status(True)
35+
time.sleep(1)
36+
37+
38+
39+
UIFLOW2 Example:
40+
41+
|example.svg|
42+
43+
.. only:: builder_html
44+
45+
|relay_core_example.m5f2|
46+
47+
class RelayUnit
48+
-----------------
49+
50+
Constructors
51+
--------------
52+
53+
.. class:: RelayUnit(io)
54+
55+
创建一个RelayUnit对象.
56+
57+
参数如下:
58+
- ``io`` 定义控制引脚。
59+
60+
61+
UIFLOW2:
62+
63+
|init.svg|
64+
65+
66+
Methods
67+
-------
68+
69+
.. method:: RelayUnit.get_status()
70+
71+
72+
获取继电器开关状态。
73+
74+
UIFLOW2:
75+
76+
|get_status.svg|
77+
78+
.. method:: RealyUnit.on()
79+
80+
闭合继电器。
81+
82+
UIFLOW2:
83+
84+
|on.svg|
85+
86+
.. method:: RealyUnit.off()
87+
88+
打开继电器。
89+
90+
UIFLOW2:
91+
92+
|off.svg|
93+
94+
.. method:: RealyUnit.set_status()
95+
96+
设置继电器状态(True 或者 false)。
97+
98+
UIFLOW2:
99+
100+
|set_status.svg|
101+
102+

0 commit comments

Comments
 (0)