Relay
#Description
This module can be used to control other circuits that are not part of your board. It could be used for example to toggle a desk lamp.
#Links
#Units
- Percent%
- State
#Aliases
- Relais
#Functions
#JavaScript / Node.js
Base class for digital output components (on/off control, blink, toggle).
#Constructor options
| Option | Type | Required | Description |
|---|---|---|---|
invert | boolean | optional | — |
pin | number | DigitalPin | required | — |
#Methods
on()→ thisTurn the component on (no arguments) or register an event listener.
off()→ thisTurn the component off
toggle()→ thisToggle the component state
set(value: 0 | 1)→ thisSet the value of the component
blink(interval: number = 500)→ thisBlink the component at a given interval (Arduino-side animation)
stop()→ thisStop any running animation (blink, pulse)
get isOn→ booleanCheck if the component is currently on
get isAnimating→ booleanCheck if an animation is running
get value→ number | undefinedfrom ComponentBaseGet the current value of the component.
#Example
import { Board, DigitalActor } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const digitalActor = new DigitalActor({ board, pin: "D5" });
digitalActor.on();
digitalActor.off();
digitalActor.toggle();See the DigitalActor reference for the full API including all methods and events.
#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.