Counter
Control
input + output
Small RAM
0.3.0
#Description
As simple as it can get, it simply counts up or down. Helpful if you want to let something happen after one or multiple other events have been triggered x times.
#Links
#Functions
#JavaScript / Node.js
Class
Counterextends EventEmitterCounter that tracks an integer value, incremented or decremented by triggers.
#Events
| Event | Parameters | Description |
|---|---|---|
change | value: number | — |
#Methods
countUp()Increment the counter by 1.
countDown()Decrement the counter by 1.
setCountTo(value: number)Set the counter to a specific value.
#Example
JavaScript
import { Board, Counter } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const counter = new Counter();#C++ (Arduino)
Virtual component that tracks a count value Emits "changed" event when count changes
#Setup
C++
#include "blokdots.h"
Counter myComponent(eventBus, MY_EVENT);#Constructor
Counter(bus, evtChanged, initialValue)| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
evtChanged | uint8_t | required |
initialValue | int | 0 |
#Methods
getValue()→ intGet current counter value
emittedValue()→ intGet emitted value (same as getValue for Counter)
countUp()Increment counter by 1
countDown()Decrement counter by 1
setCountTo(newValue)Set counter to a specific value
| Parameter | Type | Default |
|---|---|---|
newValue | int | required |