PIR Hat
支持以下产品:
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 * 8from hat import PIRHat 9 10 11label0 = None 12hat_pir_0 = None 13 14 15def hat_pir_0_active_event(pir): 16 global label0, hat_pir_0 17 label0.setText(str(hat_pir_0.get_status())) 18 19 20def setup(): 21 global label0, hat_pir_0 22 23 M5.begin() 24 label0 = Widgets.Label("label0", 9, 15, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 25 26 hat_pir_0 = PIRHat((26, 0)) 27 hat_pir_0.set_callback(hat_pir_0_active_event, hat_pir_0.IRQ_ACTIVE) 28 hat_pir_0.enable_irq() 29 30 31def loop(): 32 global label0, hat_pir_0 33 M5.update() 34 35 36if __name__ == "__main__": 37 try: 38 setup() 39 while True: 40 loop() 41 except (Exception, KeyboardInterrupt) as e: 42 try: 43 from utility import print_error_msg 44 45 print_error_msg(e) 46 except ImportError: 47 print("please update to latest firmware")
UiFlow2 应用示例
stickc_plus2_pir_hat_example.m5f2
class PIRHat
Constructors
- class PIRHat(port)
创建一个 PIRHat 对象。
- 参数如下:
portGPIO 引脚。
UIFLOW2:

Methods
- PIRHat.get_status()
获取检测状态。
UIFLOW2:

- PIRHat.enable_irq()
启用人体检测功能。
UIFLOW2:

- PIRHat.disable_irq()
禁用人体检测功能。
UIFLOW2:

- PIRHat.set_callback()
轮询方法,放置在 loop 函数中,不断检查。
UIFLOW2:


