Vibration Motor (Dimmable)
#Description
Vibration Motors simply vibrate, like the silent ringtone in a phone. They are great to give users a haptic feedback.
If you do not have a pwm pin left, you can also use the Vibration Motor component. However, it is more limited in its features.
#Links
#Units
- Percent%
#Functions
#JavaScript / Node.js
Base class for PWM output components with 0–255 value control (fade, pulse, blink animations).
#Constructor options
| Option | Type | Required | Description | Inherited from |
|---|---|---|---|---|
minValue | number | optional | — | |
maxValue | number | optional | — | |
invert | boolean | optional | — | DigitalActor |
pin | number | DigitalPin | required | — | DigitalActor |
#Methods
pulse(interval: number = 1000)→ thisPulse the component at a given interval (Arduino-side animation)
fadeTo(targetValue: number, duration: number = 1000)→ thisFade to a target value over time (Arduino-side animation)
on()→ thisfrom DigitalActorTurn the component on (no arguments) or register an event listener.
off()→ thisfrom DigitalActorTurn the component off
toggle()→ thisfrom DigitalActorToggle the component state
set(value: 0 | 1)→ thisfrom DigitalActorSet the value of the component
blink(interval: number = 500)→ thisfrom DigitalActorBlink the component at a given interval (Arduino-side animation)
stop()→ thisfrom DigitalActorStop any running animation (blink, pulse)
get isOn→ booleanfrom DigitalActorCheck if the component is currently on
get isAnimating→ booleanfrom DigitalActorCheck if an animation is running
get value→ number | undefinedfrom ComponentBaseGet the current value of the component.
#Example
import { Board, AnalogActor } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const analogActor = new AnalogActor({ board, pin: "D5" });
analogActor.set(128); // 0–255See the AnalogActor reference for the full API including all methods and events.
#C++ (Arduino)
Generic analog (PWM) output actor (LED, motor speed, etc.) Non-blocking animations: blink, fadeTo, fadeIn/out, pulse (fade up/down)
#Setup
#include "blokdots.h"
AnalogActor myComponent(5);#Constructor
AnalogActor(pin, invert, startValue)| Parameter | Type | Default |
|---|---|---|
pin | uint8_t | required |
invert | bool | false |
startValue | uint16_t | 0 |
AnalogActor(bus, pin, evtChange, invert, startValue)Constructor with EventBus for trigger support
| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
pin | uint8_t | required |
evtChange | uint8_t | required |
invert | bool | false |
startValue | uint16_t | 0 |
#Methods
stop()→ AnalogActor&Stop any running animation (blink/fade/pulse)
set(v)| Parameter | Type | Default |
|---|---|---|
v | uint16_t | required |
get()→ uint16_temittedValue()→ intGet the current value for triggers
on()off()toggle()blink(intervalMs, durationMs)→ AnalogActor&durationMs=0 => blink forever
| Parameter | Type | Default |
|---|---|---|
intervalMs | uint16_t | 500 |
durationMs | uint32_t | 0 |
blink(onMs, offMs, durationMs, highValue)→ AnalogActor&If highValue==0, we default to lastNonZero (or maxValue if lastNonZero==0).
| Parameter | Type | Default |
|---|---|---|
onMs | uint16_t | required |
offMs | uint16_t | required |
durationMs | uint32_t | required |
highValue | uint16_t | 0 |
fadeTo(target, durationMs)→ AnalogActor&Linearly fade current value to target over durationMs (non-blocking)
| Parameter | Type | Default |
|---|---|---|
target | uint16_t | required |
durationMs | uint32_t | required |
fadeIn(durationMs, target)→ AnalogActor&| Parameter | Type | Default |
|---|---|---|
durationMs | uint32_t | required |
target | uint16_t | 0 |
fadeOut(durationMs)→ AnalogActor&| Parameter | Type | Default |
|---|---|---|
durationMs | uint32_t | required |
pulse(peak, fadeInMs, fadeOutMs)→ AnalogActor&One-shot pulse: fade from CURRENT value to peak, then fade to 0.
| Parameter | Type | Default |
|---|---|---|
peak | uint16_t | required |
fadeInMs | uint16_t | required |
fadeOutMs | uint16_t | required |
pulse(peak, fadeInMs, fadeOutMs, repeat, durationMs)→ AnalogActor&Pulse with repeat option (repeat forever if durationMs=0)
| Parameter | Type | Default |
|---|---|---|
peak | uint16_t | required |
fadeInMs | uint16_t | required |
fadeOutMs | uint16_t | required |
repeat | bool | required |
durationMs | uint32_t | 0 |
See the AnalogActor reference for the full API.