muwerk mupplet Core Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
|
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) |
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).
As all light mupplets, the mupplet can be controlled using the standard light messages:
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) |
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. |
More information: PCA 9685 Light Application Notes
|
inline |
Instantiate a PCA9685 16 channel light object at a given address.
No hardware interaction is performed, until begin() is called.
name | Name of the light, used to reference it by pub/sub messages |
addr | I2C device address. Defaults to 0x40 |
activeLogic | Characterizes 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. |
|
inline |
Initialize PCA9685 hardware and start operation
_pSched | Pointer to a muwerk scheduler object, used to create worker tasks and for message pub/sub. |
_pWire | Optional pointer to a configured 'TwoWire' object. If not specified, the global object Wire is used. |
initialState | Initial 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. |
|
inline |
Set light to a given logical state.
channel | Channel number of light to set (from 0 to 15) or -1 for all channels |
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.
channel | Channel number of light to configure (from 0 to 15) or -1 for all channels |
minBrightness | Minimum brightness 0-1.0 |
maxBrightness | Maximum brightness 0-1.0 |
|
inline |
Set light mode to given LightController::Mode
channel | Channel number of light to set mode (from 0 to 15) or -1 for all channels |
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. |