Hall Effect Unit
Support the following products:
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:
cores3_hall_effect_example.m5f2
class HallEffectUnit
Constructors
Methods
- HallEffectUnit.get_status()
Get the status of the Hall Effect sensor.
UIFLOW2:
- HallEffectUnit.enable_irq()
Enable HAll Effect sensor interrupt.
UIFLOW2:
- HallEffectUnit.disable_irq()
Disable Hall Effect sensor interrupt.
UIFLOW2:
- HallEffectUnit.set_callback(handler, trigger=HallEffectUnit.IRQ_ACTIVE | HallEffectUnit.IRQ_NEGATIVE)
Set the callback function.
UIFLOW2: