Light Unit

Support the following products:

Light

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 LightUnit
 9
10
11label0 = None
12light_0 = None
13
14
15def setup():
16    global label0, light_0
17
18    M5.begin()
19    Widgets.fillScreen(0x222222)
20    label0 = Widgets.Label("label0", 132, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
21
22    light_0 = LightUnit((36, 26))
23
24
25def loop():
26    global label0, light_0
27    M5.update()
28    label0.setText(str(light_0.get_digital_value()))
29
30
31if __name__ == "__main__":
32    try:
33        setup()
34        while True:
35            loop()
36    except (Exception, KeyboardInterrupt) as e:
37        try:
38            from utility import print_error_msg
39
40            print_error_msg(e)
41        except ImportError:
42            print("please update to latest firmware")

UIFLOW2 Example:

example.png

light_core_example.m5f2

class Light

Constructors

class Light(IO1, IO2)

Create a Light object.

The parameters are:
  • IO1,IO2 Define digital and analog output pins.

UIFLOW2:

init.png

Methods

Light.get_digital_value()

Define digital and analog output pins.

UIFLOW2:

get_digital_value.png

Light.get_analog_value()

Gets the analog (returns 0-65535).

UIFLOW2:

get_analog_value.png

Light.get_ohm()

Gets the resistance value (returns an integer).

UIFLOW2:

get_ohm.png