Skip to main content

Button

Used by: Button, Flame Sensor, Motion Sensor, Tilt Switch, Touch Button, Water Sensor.

C++
#include "blokdots.h"

#Constructors

C++
Button(EventBus& bus, uint8_t pin, uint8_t evtDown, uint8_t evtUp, bool pullup = true, uint32_t debounceMs = 30, bool invert = false, uint16_t sampleIntervalMs = 2);

#Methods

MethodDescription
bool isPressed()
int emittedValue()
int onHold(uint32_t holdMs, EventBus::Handler cb, void* ctx = nullptr)Returns slot index, or -1 if full.
void setHoldMs(int slot, uint32_t ms)Optional: update hold time later
void begin()

#Example

C++
Button btn(2);           // digital pin D2

// In your event handler:
void onButtonChange(void* ctx) {
  // fires when button state changes
}