Skip to main content

LED (Dimmable)

Analog (pwm)
output
Small RAM
0.1.0

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

#Units

  • Percent%

#Aliases

  • LED (pwm)

#Functions



#JavaScript / Node.js

ClassLedDimmableextends AnalogActor

Dimmable LED component for PWM output (0-255). Extends AnalogActor with LED-specific terminology.

#Constructor options

OptionTypeRequiredDescriptionInherited from
minValuenumberoptionalAnalogActor
maxValuenumberoptionalAnalogActor
invertbooleanoptionalDigitalActor
pinnumber | DigitalPinrequiredDigitalActor

#Methods

brightness(value: number)this

Set the brightness of the LED. Alias for set() with LED-specific naming.

pulse(interval: number = 1000)thisfrom AnalogActor

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

fadeTo(targetValue: number, duration: number = 1000)thisfrom AnalogActor

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, 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

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.