Buzzer Unit
支持以下产品:
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 unit import BuzzerUnit 9 10 11buzzer_0 = None 12 13 14def setup(): 15 global buzzer_0 16 17 M5.begin() 18 Widgets.fillScreen(0x222222) 19 20 buzzer_0 = BuzzerUnit((8, 9)) 21 22 23def loop(): 24 global buzzer_0 25 M5.update() 26 if M5.Touch.getCount(): 27 buzzer_0.once(freq=4000, duty=50, duration=50) 28 29 30if __name__ == "__main__": 31 try: 32 setup() 33 while True: 34 loop() 35 except (Exception, KeyboardInterrupt) as e: 36 try: 37 from utility import print_error_msg 38 39 print_error_msg(e) 40 except ImportError: 41 print("please update to latest firmware")
UiFlow2 应用示例:
class BuzzerUnit
Constructors
- class BuzzerUnit(port)
创建一个 BuzzerUnit 对象。
- 参数如下:
port是端口的引脚编号
UiFlow2

Methods
- BuzzerUnit.once(freq=10, duty=50, duration=50)
蜂鸣器响一次。
- 参数:
UiFlow2

- BuzzerUnit.turn_off()
关闭蜂鸣器。
UiFlow2

- BuzzerUnit.deint()
反初始化蜂鸣器。
UiFlow2




