Skip to main content

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.

#Functions



#JavaScript / Node.js

ClassCounterextends EventEmitter

Counter that tracks an integer value, incremented or decremented by triggers.

#Events

EventParametersDescription
changevalue: 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)

ClassCounterextends ComponentBase

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)
ParameterTypeDefault
busEventBusrequired
evtChangeduint8_trequired
initialValueint0

#Methods

getValue()int

Get current counter value

emittedValue()int

Get 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

ParameterTypeDefault
newValueintrequired