PIR Hat
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 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 Example:
stickc_plus2_pir_hat_example.m5f2
class PIRHat
Constructors
- class PIRHat(port)
Create a PIRHat object.
- The parameters are:
portGPIO pin.
UIFLOW2:

Methods
- PIRHat.get_status()
Get detection status.
UIFLOW2:

- PIRHat.enable_irq()
Enable Human detection function.
UIFLOW2:

- PIRHat.disable_irq()
Disable Human detection function.
UIFLOW2:

- PIRHat.set_callback()
Polling method, placed in the loop function, constantly check.
UIFLOW2:


