4In8Out Module

Support the following products:

Module4In8Out

Micropython Example:

  1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
  2#
  3# SPDX-License-Identifier: MIT
  4import os, sys, io
  5import M5
  6from M5 import *
  7from module import Module4In8Out
  8import time
  9
 10
 11title0 = None
 12label0 = None
 13label1 = None
 14label2 = None
 15label3 = None
 16module_4in8out_0 = None
 17
 18
 19load_num = None
 20switch_num = None
 21state = None
 22
 23
 24def 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
 49def 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
 96if __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")

UIFLOW2 Example:

example.png

module4in8out_fire_example.m5f2

class Module4In8Out

Constructors

class Module4In8Out(address)

Init I2C Module 4In8Out I2C Address.

Parameters:

address (int|list|tuple) – I2C address of the 4In8OutModule.

UIFLOW2:

init.png

Methods

Module4In8Out.get_switch_value(switch_num) bool

Get the current value of the rotary.

Parameters:

switch_num (int) – Switch number (1 to 4).

UIFLOW2:

get_switch_value.png

Module4In8Out.get_load_state(load_num) bool

Get the state of a specific LED.

Parameters:

load_num (int) – Load number (1 to 8).

UIFLOW2:

get_load_state.png

Module4In8Out.set_load_state(load_num, state) None

Set the state of a specific Load.

Parameters:
  • load_num (int) – Load number (1 to 8).

  • state (int) – The state to set for the Load.

UIFLOW2:

set_load_state.png

Module4In8Out.get_firmware_version() int

Get the firmware version of the 4In8Out module.

UIFLOW2:

get_firmware_version.png

Module4In8Out.get_i2c_address() int

Get the current I2C address of the 4In8Out module.

UIFLOW2:

get_i2c_address.png

Module4In8Out.set_i2c_address(addr) None

Set a new I2C address for the 4In8Out module.

Parameters:

addr (int) – The new I2C address to set.

UIFLOW2:

set_i2c_address.png