Metronome
Control
input + output
Small RAM
0.4.4
#Description
This one allows you to fire events in an interval. You could use this for example to let an LED blink continuously.
#Links
#Functions
#JavaScript / Node.js
Class
Metronomeextends EventEmitterMetronome that emits a tick event at a configurable frequency (in milliseconds).
#Events
| Event | Parameters | Description |
|---|---|---|
start | state: { timestamp: number; frequency: number } | — |
tick | state: { timestamp: number; frequency: number } | — |
stop | — | — |
#Methods
start()Start the metronome. Emits a `tick` event immediately and then at every interval.
stop()Stop the metronome.
setFrequency(frequency: number)Update the tick interval in milliseconds. Takes effect immediately if already running.
#Example
JavaScript
import { Board, Metronome } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const metronome = new Metronome({ frequency: 1000 });#C++ (Arduino)
Virtual component that emits periodic tick events Emits "tick", "start", and "stop" events
#Setup
C++
#include "blokdots.h"
Metronome myComponent(eventBus, MY_EVENT, MY_EVENT, MY_EVENT);#Constructor
Metronome(bus, evtTick, evtStart, evtStop, initialFrequency)| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
evtTick | uint8_t | required |
evtStart | uint8_t | required |
evtStop | uint8_t | required |
initialFrequency | uint32_t | 1000 |
#Methods
getFrequency()→ uint32_tGet current frequency in milliseconds
playing()→ boolCheck if metronome is running
start()Start the metronome
stop()Stop the metronome
setFrequency(newFrequency)Set frequency (in milliseconds)
| Parameter | Type | Default |
|---|---|---|
newFrequency | uint32_t | required |