Buzzer 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 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 Example:
class BuzzerUnit
Constructors
- class BuzzerUnit(port)
Create an BuzzerUnit object.
- The parameters are:
port
Is the pin number of the port
UIFLOW2:
Methods
- BuzzerUnit.once(freq=10, duty=50, duration=50)
Play buzzer once.
- 参数:
UIFLOW2:
- BuzzerUnit.set_freq(freq: int)
Set the frequency of the buzzer.
- 参数:
freq (int) – The frequency of the vibration, range is 100 - 10000Hz.
UIFLOW2:
- BuzzerUnit.set_duty(duty: int)
Set the duty cycle of the buzzer.
- 参数:
duty (int) – The duty cycle of the vibration, range is 0 - 100.
UIFLOW2:
- BuzzerUnit.turn_off()
Turn off the buzzer.
UIFLOW2:
- BuzzerUnit.deint()
Deinitialize the buzzer.
UIFLOW2: