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::LightsPCA9685 Class Reference

mupplet-core PCA 9685 Light class More...

#include <mup_light_pca9685.h>

Public Member Functions

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

Detailed Description

mupplet-core PCA 9685 Light class

The PCA9685 16 channel 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 Description
<mupplet-name>/light/<channel>/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/<channel>/state on or off Current light state (on is not sent on pwm intermediate values)

Light Related Messages received by Mupplet:

Topic Message Body Description
<mupplet-name>/light/<channel>/set on, off, true, false, pct 34, 34%, 0.34 Light 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/<channel>/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 light state changes, pulse switches the light on for <duration_ms> ms, then light goes back to passive mode. blink changes the light 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 lights, 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 light 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 Integration

#define __ESP__ 1 // Platform defines required, see ustd library doc, mainpage.
#include "scheduler.h"
#include "mup_light_pca9685.h"
ustd::Scheduler sched;
ust::LightsPCA9685 pca("mylights");
void setup() {
pca.begin(&sched);
}

More information: PCA 9685 Light Application Notes

Constructor & Destructor Documentation

◆ LightsPCA9685()

ustd::LightsPCA9685::LightsPCA9685 ( String  name,
uint8_t  addr = 0x40,
bool  activeLogic = false 
)
inline

Instantiate a PCA9685 16 channel light object at a given address.

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

Parameters
nameName of the light, used to reference it by pub/sub messages
addrI2C device address. Defaults to 0x40
activeLogicCharacterizes the pysical logic-level which would turn the light on. Default is 'false', which assumes the light turns on if logic level at the corresponding port is LOW. Change to 'true', if led is turned on by physical logic level HIGH.

Member Function Documentation

◆ begin()

void ustd::LightsPCA9685::begin ( Scheduler *  _pSched,
TwoWire *  _pWire = nullptr,
bool  initialState = false 
)
inline

Initialize PCA9685 hardware and start operation

Parameters
_pSchedPointer to a muwerk scheduler object, used to create worker tasks and for message pub/sub.
_pWireOptional pointer to a configured 'TwoWire' object. If not specified, the global object Wire is used.
initialStateInitial logical state of the light: false=off, true=on. Note that this is independent of the physical output signal on the hardware 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::LightsPCA9685::set ( int8_t  channel,
bool  state 
)
inline

Set light to a given logical state.

Parameters
channelChannel number of light to set (from 0 to 15) or -1 for all channels
stateState of the light: true=on, false=off.

◆ setMinMaxWaveBrightness()

void ustd::LightsPCA9685::setMinMaxWaveBrightness ( int8_t  channel,
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
channelChannel number of light to configure (from 0 to 15) or -1 for all channels
minBrightnessMinimum brightness 0-1.0
maxBrightnessMaximum brightness 0-1.0

◆ setMode()

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

Set light mode to given LightController::Mode

Parameters
channelChannel number of light to set mode (from 0 to 15) or -1 for all channels
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: