Skip to main content

LED

Digital
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 only be turned on and off.

Have a look also at LED (Dimmable). It has more features than the LED but needs to be connected to a pwm pin.

#Units

  • Percent%
  • State

#Functions



#JavaScript / Node.js

ClassLedextends DigitalActor

LED component for digital output (on/off only). Extends DigitalActor with LED-specific terminology.

#Constructor options

OptionTypeRequiredDescriptionInherited from
invertbooleanoptional—DigitalActor
pinnumber | DigitalPinrequired—DigitalActor

#Methods

brightness(value: 0 | 1)→ this

Set the brightness of the LED (0 = off, 1 = on). Alias for on()/off() with LED-specific naming.

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 isOn→ booleanfrom DigitalActor

Check if the component is currently on

get isAnimating→ booleanfrom DigitalActor

Check if an animation is running

get value→ number | undefinedfrom ComponentBase

Get the current value of the component.

#Example

JavaScript
import { Board, Led } from "@blokdots/components";

const board = new Board("/dev/ttyACM0");
await board.open();

const led = new Led({ board, pin: "D5" });

led.on();
led.off();
led.toggle();


#C++ (Arduino)

#Setup

C++
#include "blokdots.h"

DigitalActor myComponent(5);

#Constructor

DigitalActor(pin, invert, startOn)
ParameterTypeDefault
pinuint8_trequired
invertboolfalse
startOnboolfalse
DigitalActor(bus, pin, evtChange, invert, startOn)

Constructor with EventBus for trigger support

ParameterTypeDefault
busEventBusrequired
pinuint8_trequired
evtChangeuint8_trequired
invertboolfalse
startOnboolfalse

#Methods

on()
off()
toggle()
emittedValue()→ int

Get the current state value (0 or 1) for triggers

stop()→ DigitalActor&

Stop any running animation (blink/pulse)

blink(intervalMs, durationMs)→ DigitalActor&

durationMs=0 => blink forever

ParameterTypeDefault
intervalMsuint16_t500
durationMsuint32_t0
blink(onMs, offMs, durationMs)→ DigitalActor&

durationMs=0 => blink forever

ParameterTypeDefault
onMsuint16_trequired
offMsuint16_trequired
durationMsuint32_t0
pulse(onForMs)→ DigitalActor&

One-shot pulse: ON for onForMs then OFF (no repeating)

ParameterTypeDefault
onForMsuint32_trequired

See the DigitalActor reference for the full API.