muwerk mupplet Core Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
|
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) |
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).
As all light mupplets, the mupplet can be controlled using the standard light messages:
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) |
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. |
More information: Led application notes
|
inline |
Instantiate a GPIO Led object at a given hardware port.
No hardware interaction is performed, until begin() is called.
name | Name of the led, used to reference it by pub/sub messages |
port | GPIO port number, needs to be a PWM enabled pin, if brightness, Pulse-mode or Pattern-mode with brightness levels are used. |
activeLogic | Characterizes 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. |
channel | currently 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. |
|
inline |
Initialize GPIO hardware and start operation
_pSched | Pointer to a muwerk scheduler object, used to create worker tasks and for message pub/sub. |
initialState | Initial 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. |
|
inline |
Set light to a given logical state.
state | State of the light: true=on, false=off. |
|
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.
minBrightness | Minimum brightness 0-1.0 |
maxBrightness | Maximum brightness 0-1.0 |
|
inline |
Set light mode to given LightController::Mode
mode | Light LightController::Mode |
interval_ms | Duration of blink in Mode::Blink or pulse duration. |
phase_unit | Phase 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. |
pattern | Only 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. |