Skip to main content

Vibration Motor (Dimmable)

Analog (pwm)
output
Small RAM
2.0.0

#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.

#Units

  • Percent%

#Functions



#JavaScript / Node.js

Base class for PWM output components with 0–255 value control (fade, pulse, blink animations).

#Constructor options

OptionTypeRequiredDescriptionInherited from
minValuenumberoptional
maxValuenumberoptional
invertbooleanoptionalDigitalActor
pinnumber | DigitalPinrequiredDigitalActor

#Methods

pulse(interval: number = 1000)this

Pulse the component at a given interval (Arduino-side animation)

fadeTo(targetValue: number, duration: number = 1000)this

Fade to a target value over time (Arduino-side animation)

on()thisfrom DigitalActor

Turn the component on (no arguments) or register an event listener.

off()thisfrom DigitalActor

Turn the component off

toggle()thisfrom DigitalActor

Toggle the component state

set(value: 0 | 1)thisfrom DigitalActor

Set the value of the component

blink(interval: number = 500)thisfrom DigitalActor

Blink the component at a given interval (Arduino-side animation)

stop()thisfrom DigitalActor

Stop any running animation (blink, pulse)

get isOnbooleanfrom DigitalActor

Check if the component is currently on

get isAnimatingbooleanfrom DigitalActor

Check if an animation is running

get valuenumber | undefinedfrom ComponentBase

Get the current value of the component.

#Example

JavaScript
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–255

See 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

C++
#include "blokdots.h"

AnalogActor myComponent(5);

#Constructor

AnalogActor(pin, invert, startValue)
ParameterTypeDefault
pinuint8_trequired
invertboolfalse
startValueuint16_t0
AnalogActor(bus, pin, evtChange, invert, startValue)

Constructor with EventBus for trigger support

ParameterTypeDefault
busEventBusrequired
pinuint8_trequired
evtChangeuint8_trequired
invertboolfalse
startValueuint16_t0

#Methods

stop()AnalogActor&

Stop any running animation (blink/fade/pulse)

set(v)
ParameterTypeDefault
vuint16_trequired
get()uint16_t
emittedValue()int

Get the current value for triggers

on()
off()
toggle()
blink(intervalMs, durationMs)AnalogActor&

durationMs=0 => blink forever

ParameterTypeDefault
intervalMsuint16_t500
durationMsuint32_t0
blink(onMs, offMs, durationMs, highValue)AnalogActor&

If highValue==0, we default to lastNonZero (or maxValue if lastNonZero==0).

ParameterTypeDefault
onMsuint16_trequired
offMsuint16_trequired
durationMsuint32_trequired
highValueuint16_t0
fadeTo(target, durationMs)AnalogActor&

Linearly fade current value to target over durationMs (non-blocking)

ParameterTypeDefault
targetuint16_trequired
durationMsuint32_trequired
fadeIn(durationMs, target)AnalogActor&
ParameterTypeDefault
durationMsuint32_trequired
targetuint16_t0
fadeOut(durationMs)AnalogActor&
ParameterTypeDefault
durationMsuint32_trequired
pulse(peak, fadeInMs, fadeOutMs)AnalogActor&

One-shot pulse: fade from CURRENT value to peak, then fade to 0.

ParameterTypeDefault
peakuint16_trequired
fadeInMsuint16_trequired
fadeOutMsuint16_trequired
pulse(peak, fadeInMs, fadeOutMs, repeat, durationMs)AnalogActor&

Pulse with repeat option (repeat forever if durationMs=0)

ParameterTypeDefault
peakuint16_trequired
fadeInMsuint16_trequired
fadeOutMsuint16_trequired
repeatboolrequired
durationMsuint32_t0

See the AnalogActor reference for the full API.