pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Vibrator

Example

Increases vibration intensity every second.

from m5stack import *
from m5ui import *
from uiflow import *
import time
import hat

setScreenColor(0x111111)

hat_vibrator_0 = hat.get(hat.VIBRATOR)

while True:
  hat_vibrator_0.set_duty(10)
  wait(1)
  hat_vibrator_0.set_duty(30)
  wait(1)
  hat_vibrator_0.set_duty(50)
  wait(1)
  hat_vibrator_0.set_duty(70)
  wait(1)
  hat_vibrator_0.set_duty(100)
  wait(1)
  hat_vibrator_0.turn_off()
  wait(1)
  wait_ms(2)

API

hat_vibrator_0.set_duty(50)
  • Sets the duty cycle of the vibrator (e.g., 50%), controlling the proportion of time the vibrator is active during each cycle.
hat_vibrator_0.set_freq(10)
  • Sets the vibration frequency (e.g., 10 Hz), controlling how many times per second the vibrator operates.
hat_vibrator_0.turn_off()
  • Turns off the vibrator, stopping its operation.
On This Page