TLC59116 Library
v0.2
|
#include <TLC59116.h>
Public Member Functions | |
void | _begin_trans (byte register_num) |
void | _begin_trans (byte auto_mode, byte register_num) |
int | _end_trans () |
Broadcast (TwoWire &bus, TLC59116Manager &m) | |
byte | control_register (byte register_num) |
void | control_register (byte register_num, byte data) |
void | control_register (byte count, const byte *register_num, const byte data[]) |
TLC59116_Unmanaged & | describe_actual () |
Broadcast & | enable_outputs (bool yes=true, bool with_delay=true) |
Master power switch (the TLC59116Manager sets this on/true by default) More... | |
byte | fetch_registers (byte start_r, byte count, byte registers[]) |
void | get_control_registers (byte count, const byte *register_num, byte data[]) |
bool | is_OSC_bit (byte mode1_value) |
bool | is_SUBADR_bit (byte mode1_value, byte which) |
Global Functions | |
Controlling various global features of the device (see also, the "Software Current Control" section) | |
bool | is_enable_outputs () |
Is master power on? More... | |
bool | is_enabled () |
Digital Functions | |
Analogous to DigitalWrite. Arduino DigitalWrite uses HIGH and LOW, but the device is a "sink", so "on" is actually a LOW. Thus, this library uses "on" and "off" for terminology. There are several aliases, and overloaded functions here (and for the pwm functions below). The intention was to provide natural overloads and aliases. I've shied away from using the Arduino DigitalWrite and AnalogWrite so far. These functions only change the specified channels, they'll leave other outputs, like a PWM channel alone. You can have some channels doing PWM, and some channels doing digital. | |
TLC59116 & | set_outputs (word pattern, word which) |
Only change the channels (that are marked in bit_which) to on/off as marked in bit_pattern More... | |
TLC59116 & | pattern (word bit_pattern, word bit_which=0xFFFF) |
Alias for set_outputs() More... | |
TLC59116 & | on_pattern (word pattern) |
Turn on by bit pattern. More... | |
TLC59116 & | off_pattern (word pattern) |
Turn off by bit pattern. More... | |
TLC59116 & | set (int led_num, bool offon) |
Turn one on/off, much like DigitalWrite. More... | |
TLC59116 & | on (int led_num) |
Turn one on. More... | |
TLC59116 & | off (int led_num) |
Turn one off. More... | |
PWM Functions | |
Analogous to AnalogWrite You can have some channels doing PWM, and some channels doing digital. Remember, the device is a "sink", even for PWM. Minus side of LED goes to the output pin.
| |
TLC59116 & | set_outputs (byte led_num_start, byte led_num_end, const byte brightness[]) |
PWM, start..end, list-of-brightness. More... | |
TLC59116 & | set_outputs (const byte brightness[16]) |
Set all 16 PWM according to the brightness list. More... | |
TLC59116 & | pwm (byte led_num_start, byte led_num_end, const byte brightness[]) |
Alias of set_outputs() above. More... | |
TLC59116 & | pwm (byte led_num_start, byte led_num_end, byte pwm_value) |
PWM, start..end same brightness. More... | |
TLC59116 & | pwm (const byte(&brightness)[16]) |
Set all 16 PWM according to the brightness list, same as above. More... | |
TLC59116 & | pwm (byte led_num, byte brightness) |
PWM for one channel. More... | |
Group Functions | |
If you decrease the value (blink_time or brightness) in these functions, the chip may act like the value is max for one "cycle". This causes a full-brightness result for group_pwm, and a 10 second blink-length for group_blink. I think this is because:
I recommend you only set group functions once (or only increase values). Of course, you could TLC59116Manager::reset() everytime, too. | |
TLC59116 & | group_pwm (word bit_pattern, byte brightness) |
TLC59116 & | group_blink (byte blink_period, byte on_ratio=128) |
Blink all the LEDs, at their current/last PWM setting. More... | |
TLC59116 & | group_blink (word bit_pattern, int blink_delay, int on_ratio=128) |
TLC59116 & | group_blink (double blink_length_secs, double on_percent=50.0) |
TLC59116 & | group_blink (word bit_pattern, double blink_length_secs, double on_percent=50.0) |
TLC59116 & | group_blink (unsigned int bit_pattern, int blink_length_secs, double on_percent=50.0) |
Group/Broadcast Addresses | |
Addresses for broadcast (allcall_address) and group-broadcase (SUBADR_x). Addresses should be specified as 0x60..0x6F. It is illegal to set any address to Reset_Addr (0x6B), it will be ignored with warning. | |
byte | Reset_address () |
The reset-address, unchangeable. More... | |
byte | allcall_address () |
Get broadcast address, see below to set/enable. More... | |
TLC59116 & | allcall_address (byte address, bool enable=true) |
Set and enable/disable the broadcast address (allcall_addr). More... | |
TLC59116 & | allcall_address_enable () |
Enable broadcast. More... | |
TLC59116 & | allcall_address_disable () |
Disable broadcast. More... | |
bool | is_allcall_address () |
Is broadcast enabled? More... | |
byte | SUBADR_address (byte which) |
Get the SUBADR_n address. More... | |
TLC59116 & | SUBADR_address (byte which, byte address, bool enable=true) |
Set the SUBADR_n address. More... | |
bool | is_SUBADR_address (byte which) |
Is SUBADR_n enabled? More... | |
TLC59116 & | SUBADR_address_enable (byte which) |
Enable SUBADR_n. More... | |
TLC59116 & | SUBADR_address_disable (byte which) |
Software Current Control | |
TLC59116 & | set_milliamps (byte ma, int Rext=Rext_Min) |
int | milliamps (int Rext=Rext_Min) |
Convenience | |
Since we allow function-chaining, it seems like a few convenience functions might be nice. Note all the functions (not just these convenience functions) that look like TLC59116& xxx(...) They return a reference to the device, so you can chain functions. | |
TLC59116 & | delay (int msec) |
Debugging | |
You can enable debug output by editing TLC59116.cpp, and TLC59116_Unmanaged.cpp. Add one or both: #define TLC59116_LOWLEVEL 1
#define TLC59116_DEV 1
| |
TLC59116 & | describe_shadow () |
Print the registers, as we've cached them. cf. describe_actual() More... | |
TLC59116 & | resync_shadow_registers () |
Info Functions | |
byte | address () |
Static Public Member Functions | |
static void | _begin_trans (TwoWire &bus, byte addr, byte register_num) |
static void | _begin_trans (TwoWire &bus, byte addr, byte auto_mode, byte register_num) |
static int | _end_trans (TwoWire &bus) |
static byte | best_iref (byte ma, int Rext=Rext_Min) |
static void | describe_group_mode (byte *registers) |
static void | describe_registers (byte *registers) |
static byte | i_out (byte CM, byte HC, byte CC, int Rext=Rext_Min) |
static byte | i_out (byte iref_value, int Rext=Rext_Min) |
static byte | i_out_d (byte CM, byte HC, byte D, int Rext=Rext_Min) |
static bool | is_control_register (byte register_num) |
static bool | is_default_single_addr (byte address) |
static bool | is_default_SUBADR (byte address) |
static bool | is_device_range_addr (byte address) |
static byte | is_valid_led (byte v) |
static void | LEDOUTx_CHECK (int line, byte led_num) |
static byte | LEDOUTx_Register (byte led_num) |
static byte | LEDx_digital_off_bits (byte led_num) |
static byte | LEDx_digital_on_bits (byte led_num) |
static byte | LEDx_gpwm_bits (byte led_num) |
static byte | LEDx_pwm_bits (byte led_num) |
static byte | LEDx_Register_bits (byte led_num, byte register_value) |
static byte | LEDx_Register_mask (byte led_num) |
static byte | LEDx_set_mode (byte was, byte led_num, byte mode) |
static void | LEDx_set_mode (byte registers[], byte to_what, word which) |
static byte | LEDx_to_Register_bits (byte led_num, byte out_mode) |
static byte | normalize_address (byte address) |
static byte | PWMx_Register (byte led_num) |
static byte | reverse_cc (byte CC) |
static Scan & | scan (void) |
static byte | set_with_mask (byte was, byte mask, byte new_bits) |
static void | set_with_mask (byte *was, byte mask, byte new_bits) |
static byte | SUBADRx_Register (byte i) |
Public Attributes | |
TwoWire & | i2cbus |
Static Public Attributes | |
static const byte | AllCall_Addr = Base_Addr + 0x08 |
static const byte | AllCall_Addr_Register = 0x1B |
static const byte | Auto_All = 0b10000000 |
static const byte | Auto_GRP = 0b11000000 |
static const byte | Auto_PWM = 0b10100000 |
static const byte | Auto_PWM_GRP = 0b11100000 |
static const byte | Base_Addr = 0x60 |
static const byte | Channels = 16 |
static const byte | Control_Register_Max = 0x1E |
static const byte | Control_Register_Min = 0 |
static const char * | Device = "TLC59116" |
static const byte | EFLAG1_Register = 0x1D |
static const byte | EFLAG2_Register = EFLAG1_Register + 1 |
static const byte | GRPFREQ_Register = 0x13 |
static const byte | GRPPWM_Register = 0x12 |
static const byte | IREF_CC_mask = 0b111111 |
static const byte | IREF_CM_mask = 1<<7 |
static const byte | IREF_HC_mask = 1<<6 |
static const byte | IREF_Register = 0x1C |
static const byte | LEDOUT0_Register = 0x14 |
static const byte | LEDOUT_DigitalOff = 0b00 |
static const byte | LEDOUT_DigitalOn = 0b01 |
static const byte | LEDOUT_GRPPWM = 0b11 |
static const byte | LEDOUT_Mask = 0b11 |
static const byte | LEDOUT_PWM = 0b10 |
static const byte | LEDOUTx_Max = Channels-1 |
static const byte | Max_Addr = Base_Addr + 0xF |
static const byte | MODE1_ALLCALL_mask = 0b1 |
static const byte | MODE1_OSC_mask = 0b10000 |
static const byte | MODE1_Register = 0x00 |
static const byte | MODE1_SUB1_mask = 0b1000 |
static const byte | MODE1_SUB2_mask = 0b100 |
static const byte | MODE1_SUB3_mask = 0b10 |
static const byte | MODE2_DMBLNK = 1 << 5 |
static const byte | MODE2_EFCLR = 1 << 7 |
static const byte | MODE2_OCH = 1 << 3 |
static const byte | MODE2_Register = 0x01 |
static const byte | PWM0_Register = 0x02 |
static const byte | Reset_Addr = Base_Addr + 0x0B |
static const word | Reset_Bytes = 0xA55A |
static const int | Rext_Min = 156 |
static const byte | SUBADR1 = Base_Addr + 0x09 |
static const byte | SUBADR1_Register = 0x18 |
static const byte | SUBADR2 = Base_Addr + 0x0A |
static const byte | SUBADR3 = Base_Addr + 0x0C |
Friends | |
class | TLC59116Manager |
|
inline |
|
virtual |
Master power switch (the TLC59116Manager sets this on/true by default)
It takes the device a moment to enable power, so typically leave with_delay true
Reimplemented from TLC59116.
|
inlineinherited |
Is master power on?
|
inlineinherited |
|
inherited |
Only change the channels (that are marked in bit_which) to on/off as marked in bit_pattern
(cf. on_pattern(word), on(), off() )
Examples:
pattern | on/off for each channel by bit |
which | But, only change these bits |
|
inherited |
PWM, start..end, list-of-brightness.
Examples:
led_num_start | first channel |
led_num_end | last channel |
brightness | A list of PWM values. Tolerates led_num_end>15 which wraps around |
|
inlineinherited |
Set all 16 PWM according to the brightness list.
Examples:
|
inlineinherited |
|
inlineinherited |
Turn on by bit pattern.
See set_outputs(word,word) examples for hex/binary notation hints
Examples:
|
inlineinherited |
Turn off by bit pattern.
See set_outputs(word,word) examples for hex/binary notation hints
Examples:
|
inlineinherited |
Turn one on/off, much like DigitalWrite.
Examples:
offon | true for on |
|
inlineinherited |
Turn one on.
|
inlineinherited |
Turn one off.
|
inlineinherited |
|
inlineinherited |
PWM, start..end same brightness.
Examples:
|
inlineinherited |
Set all 16 PWM according to the brightness list, same as above.
|
inlineinherited |
PWM for one channel.
Examples:
|
inherited |
Superpose group-pwm on current pwm setting (but, current should be 255 for best results)
bit_pattern | channels by bit |
brightness | superposed PWM |
|
inlineinherited |
Blink all the LEDs, at their current/last PWM setting.
Set PWM values first. To turn off blink, set channels to PWM or digital-on/off
See TLC59116& group_blink(double, double) for a version in seconds/percent.
blink_period | blink-length secs = (blink_period + 1)/24 |
on_ratio | ratio that the blink is on: on_ratio/256 |
|
inherited |
As TLC59116& group_blink(byte,byte), but you can specify the channels by bit-pattern
|
inlineinherited |
Blink all the LEDs, at their current/last PWM setting by len/%.
blink_length_secs | 0.041secs (24.00384hz) to 10.54secs (.09375hz) in steps of .04166secs |
on_percent | % of blink-cycle that is on |
|
inlineinherited |
As TLC59116& group_blink(double,double), but you can specify the channels by bit-pattern
|
inlineinherited |
Same as TLC59116& group_blink(word, double, double), but blink_length is an integer (1..10 secs)
|
inlineinherited |
The reset-address, unchangeable.
Not much you should do with this. See TLC59116Manager::reset()
|
inlineinherited |
Get broadcast address, see below to set/enable.
|
inherited |
Set and enable/disable the broadcast address (allcall_addr).
Each device can have a different allcall_address, and have it disabled/enabled.
By default, the TLC59116Manager arranges for the broadcast address to be enabled.
Examples:
|
inherited |
Enable broadcast.
|
inherited |
Disable broadcast.
|
inlineinherited |
Is broadcast enabled?
|
inlineinherited |
Get the SUBADR_n address.
Each device can have a 3 more broadcast addresses. Thus you can form various groups of the devices.
By default, the SUBADR's are disabled. You must enable them if you want to use them (see SUBADR_address(byte, byte, bool), SUBADR_address_enable(byte), SUBADR_address_disable(byte) ).
The default addresses are: are 0x69, 0x6a, 0x6b
|
inherited |
Set the SUBADR_n address.
Examples:
|
inlineinherited |
Is SUBADR_n enabled?
|
inherited |
Enable SUBADR_n.
|
inherited |
Disable SUBADR_n
We need a Rext value (the resistor attached to the Rext pin) to calculate this, e.g. 156ohms gives 120mA at reset (default), 937ohms gives 20mA. This function can use a default value of 156ohms to do the calculation.
By default, this is set to maximum current (e.g. 120mA for 156ohm). Remember that common LEDs are usually 20mA, though 10mA is becoming common (the tiny surface-mount LEDs are usually 5mA).
You probably want to set the current before you turn on any LEDs!
Note that this will tend to set the output 1milliamp low (due to rounding).
This will also clip the calculated mA to the minimum..120mA range (for Rext).
Check the extant/calculated value with milliamps().
See the section "The TLC59116 Device" for some short notes on "constant current".
Examples:
|
inlineinherited |
The calculated current setting
|
inherited |
Print the registers, as we've cached them. cf. describe_actual()
|
inherited |
Fetch the actual into our cached registers
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
staticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
staticinherited |
|
staticinherited |
|
inlinestaticinherited |
|
staticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
staticinherited |
|
inlinestaticinherited |
|
inherited |
|
inherited |
|
staticinherited |
|
inlineinherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inlineinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
inlineinherited |
|
inlinestaticinherited |
|
inlinestaticinherited |
|
friend |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
staticinherited |
|
inherited |