Hall Effect Unit

Support the following products:

HallEffect

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 HallEffectUnit
 9
10
11rect0 = None
12hall_effect_0 = None
13
14
15def hall_effect_0_active_event(hall_effect):
16    global rect0, hall_effect_0
17    rect0.setColor(color=0xFF0000, fill_c=0xFF0000)
18
19
20def hall_effect_0_negative_event(hall_effect):
21    global rect0, hall_effect_0
22    rect0.setColor(color=0x33FF33, fill_c=0x33FF33)
23
24
25def setup():
26    global rect0, hall_effect_0
27
28    M5.begin()
29    Widgets.fillScreen(0x222222)
30    rect0 = Widgets.Rectangle(145, 105, 30, 30, 0xFFFFFF, 0xFFFFFF)
31
32    hall_effect_0 = HallEffectUnit((8, 9))
33    hall_effect_0.set_callback(hall_effect_0_active_event, hall_effect_0.IRQ_ACTIVE)
34    hall_effect_0.set_callback(hall_effect_0_negative_event, hall_effect_0.IRQ_NEGATIVE)
35    hall_effect_0.enable_irq()
36    rect0.setColor(color=0x33FF33, fill_c=0x33FF33)
37
38
39def loop():
40    global rect0, hall_effect_0
41    M5.update()
42
43
44if __name__ == "__main__":
45    try:
46        setup()
47        while True:
48            loop()
49    except (Exception, KeyboardInterrupt) as e:
50        try:
51            from utility import print_error_msg
52
53            print_error_msg(e)
54        except ImportError:
55            print("please update to latest firmware")

UIFLOW2 Example:

example.png

cores3_hall_effect_example.m5f2

class HallEffectUnit

Constructors

class HallEffectUnit(port: tuple)

Create a HallEffectUnit object.

参数:

port (tuple) – Specify the port number according to the label on the unit.

UIFLOW2:

init.png

Methods

HallEffectUnit.get_status()

Get the status of the Hall Effect sensor.

UIFLOW2:

get_status.png

HallEffectUnit.enable_irq()

Enable HAll Effect sensor interrupt.

UIFLOW2:

enable_irq.png

HallEffectUnit.disable_irq()

Disable Hall Effect sensor interrupt.

UIFLOW2:

disable_irq.png

HallEffectUnit.set_callback(handler, trigger=HallEffectUnit.IRQ_ACTIVE | HallEffectUnit.IRQ_NEGATIVE)

Set the callback function.

UIFLOW2:

set_callback.png

Constants

HallEffectUnit.IRQ_ACTIVE
HallEffectUnit.IRQ_NEGATIVE

used to set the trigger mode of the interrupt.