LED (Dimmable)
#Description
LEDs are very tiny light sources. They come in a huge variety of colours. They can function as regular light or indicator of e.g. warnings. This component allows them to dim.
If you do not have a pwm pin left, you can also use the LED component. However, it is more limited in its features.
#Links
#Units
- Percent%
#Aliases
- LED (pwm)
#Functions
#JavaScript / Node.js
Dimmable LED component for PWM output (0-255). Extends AnalogActor with LED-specific terminology.
#Constructor options
| Option | Type | Required | Description | Inherited from |
|---|---|---|---|---|
minValue | number | optional | — | AnalogActor |
maxValue | number | optional | — | AnalogActor |
invert | boolean | optional | — | DigitalActor |
pin | number | DigitalPin | required | — | DigitalActor |
#Methods
brightness(value: number)→ thisSet the brightness of the LED. Alias for set() with LED-specific naming.
pulse(interval: number = 1000)→ thisfrom AnalogActorPulse the component at a given interval (Arduino-side animation)
fadeTo(targetValue: number, duration: number = 1000)→ thisfrom AnalogActorFade 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, LedDimmable } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const ledDimmable = new LedDimmable({ board, pin: "D5" });
ledDimmable.set(128); // 0–255#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.