Vibrator 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 hardware import * 9from unit import VibratorUnit 10 11 12label0 = None 13vibrator_0 = None 14 15 16def btnB_wasClicked_event(state): # noqa: N802 17 global label0, vibrator_0 18 vibrator_0.once(freq=1000, duty=15, duration=50) 19 20 21def setup(): 22 global label0, vibrator_0 23 24 M5.begin() 25 Widgets.fillScreen(0x222222) 26 label0 = Widgets.Label("play", 127, 210, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu24) 27 28 BtnB.setCallback(type=BtnB.CB_TYPE.WAS_CLICKED, cb=btnB_wasClicked_event) 29 30 vibrator_0 = VibratorUnit((36, 26)) 31 32 33def loop(): 34 global label0, vibrator_0 35 M5.update() 36 37 38if __name__ == "__main__": 39 try: 40 setup() 41 while True: 42 loop() 43 except (Exception, KeyboardInterrupt) as e: 44 try: 45 from utility import print_error_msg 46 47 print_error_msg(e) 48 except ImportError: 49 print("please update to latest firmware")
UIFLOW2 Example:
class VibratorUnit
Constructors
Methods
- VibratorUnit.once(freq=10, duty=50, duration=50) None
Play the haptic effect once on the motor.
- 参数:
UIFLOW2:
- VibratorUnit.set_freq(freq)
Set the vibration frequency.
- 参数:
freq (int) – The frequency of vibration ranges from 10-55Hz.
UIFLOW2: