ALS

ALS is used to read the built-in ambient light sensor inside the host device.

The following are the details of the host’s support for ALS:

ALS

CoreS3

CoreS3 SE

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 *
 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:

example.png

als_cores3_example.m5f2

class ALS

Important

Methods of the ALS Class heavily rely on M5.begin() M5.begin.png and M5.update() M5.update.png.

All calls to methods of ALS objects should be placed after M5.begin() M5.begin.png, and M5.update() M5.update.png should be called in the main loop.

Methods

ALS.getLightSensorData() int

Read the ambient light sensor value built into the host device.

UIFLOW2:

getLightSensorData.png