ALS

ALS 用于读取主机设备内部内置的环境光传感器。

以下是主机对 ALS 的支持详情:

ALS

CoreS3

CoreS3 SE

MicroPython 应用示例

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8
 9
10title0 = None
11label0 = None
12
13
14def setup():
15    global title0, label0
16
17    M5.begin()
18    Widgets.fillScreen(0x222222)
19    title0 = Widgets.Title("CoreS3 Als", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
20    label0 = Widgets.Label("Als:", 2, 104, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
21
22
23def loop():
24    global title0, label0
25    M5.update()
26    label0.setText(str((str("Als:") + str((M5.Als.getLightSensorData())))))
27
28
29if __name__ == "__main__":
30    try:
31        setup()
32        while True:
33            loop()
34    except (Exception, KeyboardInterrupt) as e:
35        try:
36            from utility import print_error_msg
37
38            print_error_msg(e)
39        except ImportError:
40            print("please update to latest firmware")

UiFlow2 应用示例

example.png

als_cores3_example.m5f2

class ALS

重要

ALS Class 的方法严重依赖于 M5.begin() M5.begin.pngM5.update() M5.update.png

对 ALS 对象方法的所有调用都应放在 M5.begin() M5.begin.png 之后,并且应在主循环中调用 M5.update() M5.update.png

Methods

ALS.getLightSensorData() int

读取内置于主机设备的环境光传感器数值。

UIFLOW2:

getLightSensorData.png