Skip to content

Commit 5f00c0f

Browse files
Tinyu-Zhaolbuque
authored andcommitted
lib/module: Add 4In8OutModule.
Signed-off-by: Tinyu <[email protected]>
1 parent 9dc21d5 commit 5f00c0f

File tree

8 files changed

+341
-0
lines changed

8 files changed

+341
-0
lines changed

docs/en/module/4in8out.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
4In8OutModule
3+
=============
4+
5+
.. include:: ../refs/module.module_4in8out.ref
6+
7+
Support the following products:
8+
9+
|Module4In8Out|
10+
11+
Micropython Example:
12+
13+
.. literalinclude:: ../../../examples/module/4in8out/module4in8out_fire_example.py
14+
:language: python
15+
:linenos:
16+
17+
UIFLOW2 Example:
18+
19+
|example.png|
20+
21+
.. only:: builder_html
22+
23+
|module4in8out_fire_example.m5f2|
24+
25+
class Module4In8Out
26+
-------------------
27+
28+
Constructors
29+
------------
30+
31+
.. class:: Module4In8Out(address)
32+
33+
Init I2C Module 4In8Out I2C Address.
34+
35+
:param int|list|tuple address: I2C address of the 4In8OutModule.
36+
37+
UIFLOW2:
38+
39+
|init.png|
40+
41+
42+
Methods
43+
-------
44+
45+
.. method:: Module4In8Out.get_switch_value(switch_num) -> bool
46+
47+
Get the current value of the rotary.
48+
49+
:param int switch_num: Switch number (1 to 4).
50+
51+
UIFLOW2:
52+
53+
|get_switch_value.png|
54+
55+
.. method:: Module4In8Out.get_load_state(load_num) -> bool
56+
57+
Get the state of a specific LED.
58+
59+
:param int load_num: Load number (1 to 8).
60+
61+
UIFLOW2:
62+
63+
|get_load_state.png|
64+
65+
.. method:: Module4In8Out.set_load_state(load_num, state) -> None
66+
67+
Set the state of a specific Load.
68+
69+
:param int load_num: Load number (1 to 8).
70+
:param int state: The state to set for the Load.
71+
72+
UIFLOW2:
73+
74+
|set_load_state.png|
75+
76+
.. method:: Module4In8Out.get_firmware_version() -> int
77+
78+
Get the firmware version of the 4In8Out module.
79+
80+
81+
UIFLOW2:
82+
83+
|get_firmware_version.png|
84+
85+
.. method:: Module4In8Out.get_i2c_address() -> int
86+
87+
Get the current I2C address of the 4In8Out module.
88+
89+
90+
UIFLOW2:
91+
92+
|get_i2c_address.png|
93+
94+
.. method:: Module4In8Out.set_i2c_address(addr) -> None
95+
96+
Set a new I2C address for the 4In8Out module.
97+
98+
:param int addr: The new I2C address to set.
99+
100+
UIFLOW2:
101+
102+
|set_i2c_address.png|

docs/en/module/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Module
44
.. toctree::
55
:maxdepth: 1
66

7+
4in8out.rst
78
ain4.rst
89
display.rst
910
dualkmeter.rst
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
.. |Module4In8Out| image:: https://static-cdn.m5stack.com/resource/docs/products/module/4in8out/4in8out_01.webp
3+
:target: https://docs.m5stack.com/en/module/4in8out
4+
:height: 200px
5+
:width: 200px
6+
7+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/init.png
8+
.. |get_switch_value.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_switch_value.png
9+
.. |get_load_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_load_state.png
10+
.. |set_load_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/set_load_state.png
11+
.. |get_firmware_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_firmware_version.png
12+
.. |get_i2c_address.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/get_i2c_address.png
13+
.. |set_i2c_address.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/set_i2c_address.png
14+
15+
.. |example.png| image:: https://static-cdn.m5stack.com/mpy_docs/module/4in8out/example.png
16+
17+
18+
.. |module4in8out_fire_example.m5f2| raw:: html
19+
20+
<a
21+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/module/4in8out/module4in8out_fire_example.m5f2"
22+
target="_blank"
23+
>
24+
module4in8out_fire_example.m5f2
25+
</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"V2.0","versionNumber":"V2.1.5","type":"fire","components":[{"name":"screen","type":"screen","layer":0,"screenId":"builtin","screenName":"","id":"__fire_screen","createTime":1728966513455,"x":0,"y":0,"width":320,"height":240,"backgroundColor":"#222222","size":0,"isSelected":true},{"name":"title0","type":"title","layer":1,"screenId":"builtin","screenName":"","id":"vAP0SgBJ267`=QF6","createTime":1728972403070,"x":0,"y":0,"color":"#ffffff","backgroundColor":"#0000FF","text":"4In8OutModule Example","textOffset":3,"font":"Widgets.FONTS.DejaVu18","isSelected":false},{"name":"label0","type":"label","layer":2,"screenId":"builtin","screenName":"","id":"wrY8x+1*ccWwBp`z","createTime":1728972492070,"x":1,"y":60,"color":"#ffffff","backgroundColor":"#222222","text":"Switch i Status:","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0,"isSelected":false},{"name":"label1","type":"label","layer":3,"screenId":"builtin","screenName":"","id":"o@#3GM&ymvC9&G$m","createTime":1728972496269,"x":1,"y":118,"color":"#ffffff","backgroundColor":"#222222","text":"Load i Status:","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0,"isSelected":false},{"name":"label2","type":"label","layer":4,"screenId":"builtin","screenName":"","id":"b1JU3goDbXpev98o","createTime":1728972548950,"x":1,"y":178,"color":"#ffffff","backgroundColor":"#222222","text":"I2C Addr:","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0,"isSelected":false},{"name":"label3","type":"label","layer":5,"screenId":"builtin","screenName":"","id":"aPCdX0PddAC6TCyF","createTime":1728972552698,"x":176,"y":178,"color":"#ffffff","backgroundColor":"#222222","text":"FW Version:","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0,"isSelected":false}],"resources":[{"hardware":["hardware_button","hardware_pin_button","imu","rgb","speaker"]},{"module":["module_4in8out"]}],"units":[],"hats":[],"bases":[],"i2cs":[],"blockly":"<variables><variable id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</variable><variable id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</variable><variable id=\"n#Xjnplrg,:}Xa%a.){8\">state</variable></variables><block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"50\" y=\"-10\"><mutation isBegin=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_begin\" id=\"system_m5_begin\"><next><block type=\"module_4in8out_init\" id=\"+%5!bso|cR~BDK#S}X!N\"><field name=\"NAME\">module_4in8out_0</field><value name=\"ADDR\"><shadow type=\"math_number\" id=\"-8_B!=.HKJVRW]R?3qR:\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0x45</field></shadow></value><next><block type=\"label_set_text\" id=\"3/aAGy?8ZDoTzJ`7[,4F\"><field name=\"NAME\">label2</field><value name=\"TEXT\"><shadow type=\"text\" id=\",@t|n*cOi[o;#v8Tre:c\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_add_str\" id=\"`]AG_[BNO.Tx7i{WZ/*w\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"j:_ogu^XHfp,kc1DpS@%\"><field name=\"TEXT\">I2C Addr:</field></shadow></value><value name=\"VALUE2\"><block type=\"module_4in8out_get_i2c_address\" id=\"rBai}v1MMH5Es%D:*{UX\"><field name=\"NAME\">module_4in8out_0</field></block></value></block></value><next><block type=\"label_set_text\" id=\"`a9A?)L[e:0E.c(nIHpa\"><field name=\"NAME\">label3</field><value name=\"TEXT\"><shadow type=\"text\" id=\"o?tZnq=RUQ2eo.;]VL/g\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_add_str\" id=\"7Ec9B;mIYIG}BntYLf#A\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"A`abVdw)!MA1oLkzT{li\"><field name=\"TEXT\">FW Version:</field></shadow></value><value name=\"VALUE2\"><block type=\"module_4in8out_get_firmware_version\" id=\"aP(Ee69K_|qy{Zn|#6V6\"><field name=\"NAME\">module_4in8out_0</field></block></value></block></value><next><block type=\"variables_set\" id=\"KIXXQ-TK5%+@9V:D;qdU\"><field name=\"VAR\" id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</field><value name=\"VALUE\"><block type=\"math_number\" id=\"Jn]YTi59]bH-/b$u6E;0\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></block></value><next><block type=\"variables_set\" id=\"6IkJD,!H{?}NG;UI3Fp{\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field><value name=\"VALUE\"><block type=\"math_number\" id=\";Pr.:UKX)=`.Hg(q]XJ5\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></block></value><next><block type=\"variables_set\" id=\"zGAE4Z)Es8t8$WNf`|2#\"><field name=\"VAR\" id=\"n#Xjnplrg,:}Xa%a.){8\">state</field><value name=\"VALUE\"><block type=\"math_number\" id=\"S.tS_J|nOhl(0yk~t}Z8\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type=\"basic_on_loop\" id=\"loop_block\" deletable=\"false\" x=\"50\" y=\"330\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"system_m5_update\"><next><block type=\"variables_set\" id=\"mvS99@GI_TOLX{rO*Ayr\"><field name=\"VAR\" id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</field><value name=\"VALUE\"><block type=\"math_arithmetic\" id=\"Z6k5$!rd,Wa!8X]NXQG.\"><field name=\"OP\">ADD</field><value name=\"A\"><shadow type=\"math_number\" id=\"gf@BNne8!UdSk27#GFDc\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow><block type=\"variables_get\" id=\"j^6mcx}?zH`jZR`ofZmk\"><field name=\"VAR\" id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</field></block></value><value name=\"B\"><shadow type=\"math_number\" id=\"ud5+1[re@93s-%8~5|3h\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow></value></block></value><next><block type=\"variables_set\" id=\"Tj;zMe{]vo0_Xf0$`?#g\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field><value name=\"VALUE\"><block type=\"math_arithmetic\" id=\"M@}1#y?1p@B+aio0`%~O\"><field name=\"OP\">ADD</field><value name=\"A\"><shadow type=\"math_number\" id=\"gf@BNne8!UdSk27#GFDc\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow><block type=\"variables_get\" id=\"5Nyi?ZO$7GSi_aYQt~JJ\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field></block></value><value name=\"B\"><shadow type=\"math_number\" id=\"OhxJHM($eawSlN/3~3:m\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow></value></block></value><next><block type=\"controls_if\" id=\"_Z5:u`[T]{O]%w$I[2{T\"><value name=\"IF0\"><block type=\"logic_compare\" id=\"g;e0{B:]LA~V}h2fGkca\"><field name=\"OP\">GT</field><value name=\"A\"><block type=\"variables_get\" id=\"S?QPfIR2mM!)JW!0I}xy\"><field name=\"VAR\" id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"NFUMT(lIhODUR)CN}2oc\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">8</field></block></value></block></value><statement name=\"DO0\"><block type=\"variables_set\" id=\"O?wh|d3:X$`88tc2S:Y$\"><field name=\"VAR\" id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</field><value name=\"VALUE\"><block type=\"math_number\" id=\"T!E0*jCIszzpIQa=#[9N\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></block></value><next><block type=\"variables_set\" id=\"=:=8!}S7@`{@d7qy*RF7\"><field name=\"VAR\" id=\"n#Xjnplrg,:}Xa%a.){8\">state</field><value name=\"VALUE\"><block type=\"logic_negate\" id=\"Xvh0#GQ%^K9_tXS?Aux)\"><value name=\"BOOL\"><block type=\"variables_get\" id=\"52{o]DvsS|(|%*idv2oC\"><field name=\"VAR\" id=\"n#Xjnplrg,:}Xa%a.){8\">state</field></block></value></block></value></block></next></block></statement><next><block type=\"controls_if\" id=\"I]PE)jt}Fs!zNtsZWvL^\"><value name=\"IF0\"><block type=\"logic_compare\" id=\"(0nu5:W;~IBaE0gP:pQU\"><field name=\"OP\">GT</field><value name=\"A\"><block type=\"variables_get\" id=\"E?f~m$Axu]}4tv1w{kQ6\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"oKroT1?Ye1Fgx7q|SG98\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">4</field></block></value></block></value><statement name=\"DO0\"><block type=\"variables_set\" id=\"-7xcafBU^=}y1.E0Hf|g\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field><value name=\"VALUE\"><block type=\"math_number\" id=\"eZV}N5o-V.iAGvn{sYy4\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></block></value></block></statement><next><block type=\"module_4in8out_set_load_state\" id=\"[email protected]@xp/O12uO3xL/\"><field name=\"NAME\">module_4in8out_0</field><value name=\"CHANNEL\"><shadow type=\"module_4in8out_output_channel_option\" id=\"E/e6pZ]W=eYtomgCr]$G\"><field name=\"VALUE\">1</field></shadow><block type=\"variables_get\" id=\"iDdsw+je$d0fdk{Pe%WQ\"><field name=\"VAR\" id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</field></block></value><value name=\"STATE\"><shadow type=\"module_4in8out_value_option\" id=\"-V3wwL5^P+Z[En!J[QdW\"><field name=\"VALUE\">1</field></shadow><block type=\"variables_get\" id=\"$0t2_{J_0Z3%0O(ivnqp\"><field name=\"VAR\" id=\"n#Xjnplrg,:}Xa%a.){8\">state</field></block></value><next><block type=\"label_set_text\" id=\"#Ss:x$!LJ(y@OkH)dO_+\"><field name=\"NAME\">label0</field><value name=\"TEXT\"><shadow type=\"text\" id=\"#hAZusQa^ka,31W-I}fy\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_add_str\" id=\"M^Li`SDXapQ(PzqiFx|f\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"Ql=o!ipj$=IF/GS5c^3L\"><field name=\"TEXT\">Switch </field></shadow></value><value name=\"VALUE2\"><block type=\"text_add_str\" id=\"vfGM=1DFJKVekYa@Qmlx\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"Jd=T9p},o]ro;~E1lmV@\"><field name=\"TEXT\"> Status:</field></shadow><block type=\"variables_get\" id=\"Atm*DJ:o:$,hKUSh[6K.\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field></block></value><value name=\"VALUE2\"><block type=\"text_add_str\" id=\"WOk)_V96$1VOaq/sf2gU\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"gr`af~fa]M*(4LFdgtLf\"><field name=\"TEXT\"> Status:</field></shadow></value><value name=\"VALUE2\"><block type=\"module_4in8out_get_switch_value\" id=\"ZK^SU,]O0biX`jI#,xS^\"><field name=\"NAME\">module_4in8out_0</field><value name=\"CHANNEL\"><shadow type=\"module_4in8out_input_channel_option\" id=\"WVmn0wVOT5A6^%ClCV;,\"><field name=\"VALUE\">1</field></shadow><block type=\"variables_get\" id=\"sWF0bjM:4C5*Z4xJQ#o(\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field></block></value></block></value></block></value></block></value></block></value><next><block type=\"label_set_text\" id=\"CaF61(|#_zbAT;*mP09M\"><field name=\"NAME\">label1</field><value name=\"TEXT\"><shadow type=\"text\" id=\"#hAZusQa^ka,31W-I}fy\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_add_str\" id=\"qD{aau+7!~-@3$x$1/HT\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"1P.ew{S]FBNXL)Fjmh0{\"><field name=\"TEXT\">Load </field></shadow></value><value name=\"VALUE2\"><block type=\"text_add_str\" id=\"~YK-Y(F6~)#^*8LFAe6F\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"Jd=T9p},o]ro;~E1lmV@\"><field name=\"TEXT\"> Status:</field></shadow><block type=\"variables_get\" id=\"pVO{FXSb!?TFT!UmP$qg\"><field name=\"VAR\" id=\"|$DZdm.vh8}hr/}W^B2v\">load_num</field></block></value><value name=\"VALUE2\"><block type=\"text_add_str\" id=\"~QKB)e2N/}ec^~+qk3O4\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"QyJi~R0ZQT#/S$sw|4eh\"><field name=\"TEXT\"> Status:</field></shadow></value><value name=\"VALUE2\"><block type=\"module_4in8out_get_load_state\" id=\"mRlJS_6x{JCcSDH:FW5J\"><field name=\"NAME\">module_4in8out_0</field><value name=\"CHANNEL\"><shadow type=\"module_4in8out_output_channel_option\" id=\"-^y+j9X5|(:u;?/zQu_t\"><field name=\"VALUE\">1</field></shadow><block type=\"variables_get\" id=\"EFwQe7{)Yh*fUb:@7u,9\"><field name=\"VAR\" id=\"Nn(Lb--7.W/)p2dIGLZx\">switch_num</field></block></value></block></value></block></value></block></value></block></value><next><block type=\"time_sleep_second\" id=\"s/HSoiUnQ-;VSx85|*N]\"><value name=\"SECOND\"><shadow type=\"math_number\" id=\"c`04-QxgZ(:t~A~MyG[(\"><mutation max=\"Infinity\" min=\"0\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block>","screen":[{"simulationName":"Built-in","type":"builtin","width":320,"height":240,"scale":0.78,"screenName":"","blockId":"","screenColorType":0,"id":"builtin","createTime":1728966513453}],"logicWhenNum":0,"customList":[]}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import os, sys, io
5+
import M5
6+
from M5 import *
7+
from module import Module4In8Out
8+
import time
9+
10+
11+
title0 = None
12+
label0 = None
13+
label1 = None
14+
label2 = None
15+
label3 = None
16+
module_4in8out_0 = None
17+
18+
19+
load_num = None
20+
switch_num = None
21+
state = None
22+
23+
24+
def setup():
25+
global title0, label0, label1, label2, label3, module_4in8out_0, load_num, switch_num, state
26+
27+
M5.begin()
28+
Widgets.fillScreen(0x222222)
29+
title0 = Widgets.Title("4In8OutModule Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
30+
label0 = Widgets.Label(
31+
"Switch i Status:", 1, 60, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
32+
)
33+
label1 = Widgets.Label(
34+
"Load i Status:", 1, 118, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
35+
)
36+
label2 = Widgets.Label("I2C Addr:", 1, 178, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
37+
label3 = Widgets.Label(
38+
"FW Version:", 176, 178, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18
39+
)
40+
41+
module_4in8out_0 = Module4In8Out(address=0x45)
42+
label2.setText(str((str("I2C Addr:") + str((module_4in8out_0.get_i2c_address())))))
43+
label3.setText(str((str("FW Version:") + str((module_4in8out_0.get_firmware_version())))))
44+
load_num = 1
45+
switch_num = 1
46+
state = 1
47+
48+
49+
def loop():
50+
global title0, label0, label1, label2, label3, module_4in8out_0, load_num, switch_num, state
51+
M5.update()
52+
load_num = load_num + 1
53+
switch_num = switch_num + 1
54+
if load_num > 8:
55+
load_num = 1
56+
state = not state
57+
if switch_num > 4:
58+
switch_num = 1
59+
module_4in8out_0.set_load_state(load_num, state)
60+
label0.setText(
61+
str(
62+
(
63+
str("Switch ")
64+
+ str(
65+
(
66+
str(switch_num)
67+
+ str(
68+
(
69+
str(" Status:")
70+
+ str((module_4in8out_0.get_switch_value(switch_num)))
71+
)
72+
)
73+
)
74+
)
75+
)
76+
)
77+
)
78+
label1.setText(
79+
str(
80+
(
81+
str("Load ")
82+
+ str(
83+
(
84+
str(load_num)
85+
+ str(
86+
(str(" Status:") + str((module_4in8out_0.get_load_state(switch_num))))
87+
)
88+
)
89+
)
90+
)
91+
)
92+
)
93+
time.sleep(1)
94+
95+
96+
if __name__ == "__main__":
97+
try:
98+
setup()
99+
while True:
100+
loop()
101+
except (Exception, KeyboardInterrupt) as e:
102+
try:
103+
from utility import print_error_msg
104+
105+
print_error_msg(e)
106+
except ImportError:
107+
print("please update to latest firmware")

m5stack/libs/module/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"HMIModule": "hmi",
1313
"IotBaseCatmModule": "iot_base_catm",
1414
"LoraModule": "lora",
15+
"Module4In8Out": "module_4in8out",
1516
"PLUSModule": "plus",
1617
"PPSModule": "pps",
1718
"RCAModule": "rca",

m5stack/libs/module/manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"iot_base_catm.py",
1515
"lora.py",
1616
"mbus.py",
17+
"module_4in8out.py",
1718
"module_helper.py",
1819
"plus.py",
1920
"pps.py",

0 commit comments

Comments
 (0)