LED
#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.
#Links
#Units
- Percent%
- State
#Functions
#JavaScript / Node.js
LED component for digital output (on/off only). Extends DigitalActor with LED-specific terminology.
#Constructor options
| Option | Type | Required | Description | Inherited from |
|---|---|---|---|---|
invert | boolean | optional | — | DigitalActor |
pin | number | DigitalPin | required | — | DigitalActor |
#Methods
brightness(value: 0 | 1)→ thisSet the brightness of the LED (0 = off, 1 = on). Alias for on()/off() with LED-specific naming.
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, 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
#include "blokdots.h"
DigitalActor myComponent(5);#Constructor
DigitalActor(pin, invert, startOn)| Parameter | Type | Default |
|---|---|---|
pin | uint8_t | required |
invert | bool | false |
startOn | bool | false |
DigitalActor(bus, pin, evtChange, invert, startOn)Constructor with EventBus for trigger support
| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
pin | uint8_t | required |
evtChange | uint8_t | required |
invert | bool | false |
startOn | bool | false |
#Methods
on()off()toggle()emittedValue()→ intGet 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
| Parameter | Type | Default |
|---|---|---|
intervalMs | uint16_t | 500 |
durationMs | uint32_t | 0 |
blink(onMs, offMs, durationMs)→ DigitalActor&durationMs=0 => blink forever
| Parameter | Type | Default |
|---|---|---|
onMs | uint16_t | required |
offMs | uint16_t | required |
durationMs | uint32_t | 0 |
pulse(onForMs)→ DigitalActor&One-shot pulse: ON for onForMs then OFF (no repeating)
| Parameter | Type | Default |
|---|---|---|
onForMs | uint32_t | required |
See the DigitalActor reference for the full API.