DLight Unit

支持以下产品:

Dlight

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

UIFLOW2 Example:

example.png

dlight_core_example.m5f2

class DLight

Constructors

class DLightUnit(i2c, address: int = 0x23)

创建一个DLight对象.

参数:
  • i2c – the I2C object.

  • address – the I2C address of the device. Default is 0x23.

UIFLOW2:

init.svg

Methods

DLightUnit.get_lux()

获取光照强度。

UIFLOW2:

get_lux.svg

DLightUnit.configure()

配置测量模式(持续测量/单次测量)和分辨率。

UIFLOW2:

configure.svg