Reflective IR 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 ReflectiveIRUnit 9 10 11rect0 = None 12reflectiveir_0 = None 13 14 15def reflectiveir_0_not_detected_event(reflectiveir): 16 global rect0, reflectiveir_0 17 rect0.setColor(color=0x33CC00, fill_c=0x33CC00) 18 19 20def reflectiveir_0_detected_event(reflectiveir): 21 global rect0, reflectiveir_0 22 rect0.setColor(color=0xCC0000, fill_c=0xCC0000) 23 24 25def setup(): 26 global rect0, reflectiveir_0 27 28 M5.begin() 29 rect0 = Widgets.Rectangle(44, 97, 30, 30, 0xFFFFFF, 0xFFFFFF) 30 31 reflectiveir_0 = ReflectiveIRUnit((33, 32)) 32 reflectiveir_0.set_callback( 33 reflectiveir_0_not_detected_event, ReflectiveIRUnit.EVENT_NOT_DETECTED 34 ) 35 reflectiveir_0.set_callback(reflectiveir_0_detected_event, ReflectiveIRUnit.EVENT_DETECTED) 36 reflectiveir_0.enable_irq() 37 38 39def loop(): 40 global rect0, reflectiveir_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:
stickc_plus_reflectiverir_example.m5f2
class ReflectiveIRUnit
Constructors
Methods
- ReflectiveIRUnit.get_analog_value() int
This method allows read the ADC value of the Reflective IR Unit and return an integer value. The value ranges from 0 to 65535.
UIFLOW2: