Vibrator Unit

Support the following products:

Vibrator

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:

example.png

core_vibrator_example.m5f2

class VibratorUnit

Constructors

class VibratorUnit(port: tuple = (26, 0))

Create an VibratorUnit object.

参数:

port – The port where the VibratorUnit is connected to.

UIFLOW2:

init.png

Methods

VibratorUnit.once(freq=10, duty=50, duration=50) None

Play the haptic effect once on the motor.

参数:
  • freq (int) – The frequency of vibration ranges from 10-55Hz.

  • duty (int) – The duty cycle of vibration ranges from 0-100, representing the corresponding percentage.

  • duration (int) – The duration of the vibration effect, in milliseconds.

UIFLOW2:

once.png

VibratorUnit.set_freq(freq)

Set the vibration frequency.

参数:

freq (int) – The frequency of vibration ranges from 10-55Hz.

UIFLOW2:

set_freq.png

VibratorUnit.set_duty(freq) None

Set the vibration duty cycle.

参数:

duty (int) – The duty cycle of vibration ranges from 0-100, representing the corresponding percentage.

UIFLOW2:

set_duty.png

VibratorUnit.turn_off() None

Turn off the motor.

UIFLOW2:

turn_off.png

VibratorUnit.deint() None

Deinitialize the motor.

UIFLOW2:

deinit.png