Skip to main content

AnalogSensor

Generic analog input with thresholded "change" events (potentiometer-style)

Used by: Air Quality Sensor, Brightness Sensor, Moisture Sensor, Potentiometer, Slide Potentiometer, Sound Sensor, Temperature Sensor.

C++
#include "blokdots.h"

#Constructors

C++
AnalogSensor(EventBus& bus, uint8_t pin, uint8_t evtChange, int threshold = 5, uint16_t intervalMs = 5, uint16_t minEmitIntervalMs = 20, int quantizeStep = 0, bool invert = false);

#Methods

MethodDescription
int value()Most recent sampled value (may change even if not emitted yet)
int emittedValue()The value that was last emitted with evtChange (use this in handlers!)

#Example

C++
// AnalogSensor requires EventBus (wired automatically in generated code)
AnalogSensor sensor(eventBus, A0, EVT_SENSOR_CHANGE);

void onSensorChange(void* ctx) {
  int value = sensor.emittedValue();  // 0–1023
}