muwerk mupplet Sensor Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications for sensors
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ustd::IlluminanceLdr Class Reference

mupplet-sensor analog LDR illumance sensor More...

#include <mup_illuminance_ldr.h>

Public Member Functions

 IlluminanceLdr (String name, uint8_t port, FilterMode filterMode=FilterMode::MEDIUM)
 
double getUnitIlluminance ()
 
void begin (Scheduler *_pSched, uint32_t _pollRateMs=2000)
 

Detailed Description

mupplet-sensor analog LDR illumance sensor

The illuminance_ldr mupplet measures illuminance using a simple analog LDR (light dependent resistor)

Messages sent by illuminance_ldr mupplet:

topic message body comment
<mupplet-name>/sensor/unitilluminance normalized illuminance [0.0-1.0] Float value encoded as string
<mupplet-name>/sensor/mode FAST, MEDIUM, or LONGTERM Integration time for illuminance values

Messages received by illuminance_ldr mupplet:

topic message body comment
<mupplet-name>/sensor/unitilluminance/get - Causes current value to be sent with.
<mupplet-name>/sensor/mode/get - Returns filterMode: FAST, MEDIUM, or LONGTERM
<mupplet-name>/sensor/mode/set FAST, MEDIUM, or LONGTERM Set integration time for illuminance values

Hardware: LDR, 10kΩ resistor

Sample code

#define __ESP__ 1
#include "scheduler.h"
#include "mup_illuminance_ldr.h"
ustd::Scheduler sched;
ustd::IlluminanceLdr ldr("myLDR",A0);
void task0(String topic, String msg, String originator) {
if (topic == "myLDR/sensor/unitilluminance") {
Serial.print("Illuminance: ");
Serial.prinln(msg); // String float [0.0, ..., 1.0]
}
}
void setup() {
ldr.begin(&sched);
}
mupplet-sensor analog LDR illumance sensor
Definition: mup_illuminance_ldr.h:101

Note: For ESP32 make sure to use a port connected to ADC #1, since ADC #2 conflicts with Wifi and ports connected to ADC #2 cannot be used concurrently with Wifi!

Constructor & Destructor Documentation

◆ IlluminanceLdr()

ustd::IlluminanceLdr::IlluminanceLdr ( String  name,
uint8_t  port,
FilterMode  filterMode = FilterMode::MEDIUM 
)
inline

Instantiate an LDR sensor mupplet

Parameters
nameName used for pub/sub messages
portGPIO port with A/D converter capabilities.
filterModeFAST, MEDIUM or LONGTERM filtering of sensor values

Member Function Documentation

◆ begin()

void ustd::IlluminanceLdr::begin ( Scheduler *  _pSched,
uint32_t  _pollRateMs = 2000 
)
inline

Start processing of A/D input from LDR

◆ getUnitIlluminance()

double ustd::IlluminanceLdr::getUnitIlluminance ( )
inline

Get current unit illumance

Returns
Unit-Illuminance [0.0(dark) - 1.0(max. illuminance)]

The documentation for this class was generated from the following file: