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

mupplet-core GPIO Light class More...

#include <mup_light.h>

Public Member Functions

 Light (String name, uint8_t port, bool activeLogic=false, uint8_t channel=0)
 
void begin (Scheduler *_pSched, bool initialState=false)
 
void set (bool state)
 
void setMode (LightController::Mode mode, unsigned int interval_ms=1000, double phase_unit=0.0, String pattern="")
 
void setMinMaxWaveBrightness (double minBrightness, double maxBrightness)
 

Detailed Description

mupplet-core GPIO Light class

The GPIO Light class allows control of standard Leds (or lights) with digital and PWM control.

Supported modes are: on/off (mode: Passive), brightness (mode: Passive, with PWM), wave (soft oszillation, mode: Wave), one-time pulse (mode: Pulse), and repeating, user-selectable patterns (mode: Pattern).

Messages

As all light mupplets, the mupplet can be controlled using the standard light messages:

Light Related Messages sent by Mupplet:

topic message body comment
<mupplet-name>/light/unitbrightness normalized brightness [0.0-1.0] 0.34: Float value encoded as string. Not send on automatic changes (e.g. pulse mode)
<mupplet-name>/light/state on or off current led state (on is not sent on pwm intermediate values)

Light Related Messages received by Mupplet:

topic message body comment
<mupplet-name>/light/set on, off, true, false, pct 34, 34%, 0.34 Led can be set fully on or off with on/true and off/false. A fractional brightness of 0.34 (within interval [0.0, 1.0]) can be sent as either pct 34, or 0.34, or 34%.
<mupplet-name>/light/mode/set passive, pulse <duration_ms>, blink <intervall_ms>[,<phase-shift>], pattern <pattern>[,<intervall>[,<phase>]] or wave <intervall_ms>[,<phase-shift>] Mode passive does no automatic led state changes, pulse switches the led on for <duration_ms> ms, then led goes back to passive mode. blink changes the led state very interval_ms on/off, wave uses pwm to for soft changes between on and off states. Optional comma-speratated phase [0.0, ..., 1.0] can be added as a phase-shift. Two leds, one with wave 1000 and one with wave 1000,0.5 blink inverse. Patterns can be specified as string containing +,-,0..9 or r. + is led on during <intervall> ms, - is off, 0..9 brightness-level. An r at the end of the pattern repeats the pattern. "pattern +-+-+-+++-+++-+++-+-+-+---r,100" lets the board signal SOS.

Sample Led Integration

#define __ESP__ 1 // Platform defines required, see ustd library doc, mainpage.
#include "scheduler.h"
#include "mup_light.h"
ustd::Scheduler sched;
ust::Light led("myled",13);
void setup() {
led.begin(&sched);
}

More information: Led application notes

Constructor & Destructor Documentation

◆ Light()

ustd::Light::Light ( String  name,
uint8_t  port,
bool  activeLogic = false,
uint8_t  channel = 0 
)
inline

Instantiate a GPIO Led object at a given hardware port.

No hardware interaction is performed, until begin() is called.

Parameters
nameName of the led, used to reference it by pub/sub messages
portGPIO port number, needs to be a PWM enabled pin, if brightness, Pulse-mode or Pattern-mode with brightness levels are used.
activeLogicCharacterizes the pysical logicl-level which would turn the led on. Default is 'false', which assumes the led turns on if logic level at the GPIO port is LOW. Change to 'true', if led is turned on by physical logic level HIGH.
channelcurrently ESP32 only, can be ignored for all other platforms. ESP32 requires assignment of a system-wide unique channel number (0..15) for each led in the system. So for ESP32 both the GPIO port number and a unique channel id are required.

Member Function Documentation

◆ begin()

void ustd::Light::begin ( Scheduler *  _pSched,
bool  initialState = false 
)
inline

Initialize GPIO hardware and start operation

Parameters
_pSchedPointer to a muwerk scheduler object, used to create worker tasks and for message pub/sub.
initialStateInitial logical state of the light: false=off, true=on. Note that this is independent of the physical output signal on the GPIO port: if a LOW or HIGH signal is required to switch the light on, is defined by the constructor's activeLogic parameter.

◆ set()

void ustd::Light::set ( bool  state)
inline

Set light to a given logical state.

Parameters
stateState of the light: true=on, false=off.

◆ setMinMaxWaveBrightness()

void ustd::Light::setMinMaxWaveBrightness ( double  minBrightness,
double  maxBrightness 
)
inline

Set minimum and maximum brightness in wave LightController::Mode

Useful to compensate, if a light stays at similar brightness for a range of input values.

Parameters
minBrightnessMinimum brightness 0-1.0
maxBrightnessMaximum brightness 0-1.0

◆ setMode()

void ustd::Light::setMode ( LightController::Mode  mode,
unsigned int  interval_ms = 1000,
double  phase_unit = 0.0,
String  pattern = "" 
)
inline

Set light mode to given LightController::Mode

Parameters
modeLight LightController::Mode
interval_msDuration of blink in Mode::Blink or pulse duration.
phase_unitPhase difference used to synchronize different lights in Wave or blink mode. A phase_unit of 0 synchronizes the given lights. phase-difference is in [0.0-1.0]. A phase difference of 0.5 (180 degrees) between two lights would let lights blink reversed.
patternOnly in Mode::Pattern: a pattern string consisting of the characters '+' (on), '-' (off), '0'-'9' (brightness 0%-100%), or at the end of the string 'r' for endless repeat. Intervall_ms is the time for each pattern step. Example "++-r" with intervall_ms=100 lights the led for 200ms on, 100ms off and repeats. "1---------r" makes a faint 100ms flash every second. "0135797531r" simulates a PWM wave.

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