LP50XX Driver  V1.0
Library for interaction with the LP5009 and LP5012 LED driver
LP50XX.h
Go to the documentation of this file.
1 
11 #ifndef __LP50XX_H
12 #define __LP50XX_H
13 
14 #include <Arduino.h>
15 #include <Wire.h>
16 
17 #define DEFAULT_ADDRESS 0x14
18 #define BROADCAST_ADDRESS 0x0C
19 
21  RGB,
22  GRB,
23  BGR,
24  RBG,
25  GBR,
26  BRG,
27 };
28 
30  LED_0 = 1,
31  LED_1 = 2,
32  LED_2 = 4,
33  LED_3 = 8
34 };
35 
37  LED_GLOBAL_ON = 0 << 0,
38  LED_GLOBAL_OFF = 1 << 0,
39  MAX_CURRENT_25mA = 0 << 1,
40  MAX_CURRENT_35mA = 1 << 1,
42  PWM_DITHERING_ON = 1 << 2,
43  AUTO_INC_OFF = 0 << 3,
44  AUTO_INC_ON = 1 << 3,
45  POWER_SAVE_OFF = 0 << 4,
46  POWER_SAVE_ON = 1 << 4,
47  LOG_SCALE_OFF = 0 << 5,
48  LOG_SCALE_ON = 1 << 5
49 };
50 
54 };
55 
56 // Register definitions
57 #define DEVICE_CONFIG0 0x00 // Chip_EN
58 #define DEVICE_CONFIG1 0x01 // Configurations for Log_scale, Power_save, Auto_inc, PWM_dithering, Max_current_option and LED_Global_off
59 #define LED_CONFIG0 0x02 // Contains the BANK configurations
60 #define BANK_BRIGHTNESS 0x03 // Contains the BANK brightness level
61 #define BANK_A_COLOR 0x04 // Contains the BANK A color value
62 #define BANK_B_COLOR 0x05 // Contains the BANK B color value
63 #define BANK_C_COLOR 0x06 // Contains the BANK C color value
64 #define LED0_BRIGHTNESS 0x07 // Contains the brightness level for LED 0
65 #define LED1_BRIGHTNESS 0x08 // Contains the brightness level for LED 1
66 #define LED2_BRIGHTNESS 0x09 // Contains the brightness level for LED 2
67 #define LED3_BRIGHTNESS 0x0A // Contains the brightness level for LED 3 (only on the LP5012)
68 #define OUT0_COLOR 0x0B // Contains the color value for output 0
69 #define OUT1_COLOR 0x0C // Contains the color value for output 1
70 #define OUT2_COLOR 0x0D // Contains the color value for output 2
71 #define OUT3_COLOR 0x0E // Contains the color value for output 3
72 #define OUT4_COLOR 0x0F // Contains the color value for output 4
73 #define OUT5_COLOR 0x10 // Contains the color value for output 5
74 #define OUT6_COLOR 0x11 // Contains the color value for output 6
75 #define OUT7_COLOR 0x12 // Contains the color value for output 7
76 #define OUT8_COLOR 0x13 // Contains the color value for output 8
77 #define OUT9_COLOR 0x14 // Contains the color value for output 9 (only on the LP5012)
78 #define OUT10_COLOR 0x15 // Contains the color value for output 10 (only on the LP5012)
79 #define OUT11_COLOR 0x16 // Contains the color value for output 11 (only on the LP5012)
80 #define RESET_REGISTERS 0x17 // Resets all the registers to their default values
81 
85 class LP50XX
86 {
87  public:
88  LP50XX(void); // Constructor
89  LP50XX(LED_Configuration ledConfiguration); // Constructor with a specific led configuration
90  LP50XX(uint8_t enablePin); // Constructor with enable pin
91  LP50XX(LED_Configuration ledConfiguration, uint8_t enablePin); // Constructor with a specific led configuration and an enable pin
92 
96  void Begin(uint8_t i2c_address = DEFAULT_ADDRESS); // Initialize the driver
97  void Reset();
99 
103  void Configure(uint8_t configuration, EAddressType addressType = EAddressType::Normal);
104  void SetScaling(uint8_t scaling);
105  void SetPowerSaving(uint8_t powerSave);
106  void SetAutoIncrement(uint8_t autoInc);
107  void SetPWMDithering(uint8_t dithering);
108  void SetMaxCurrentOption(uint8_t option);
109  void SetGlobalLedOff(uint8_t value);
110 
111  void SetEnablePin(uint8_t enablePin);
112  void SetLEDConfiguration(LED_Configuration ledConfiguration);
113  void SetI2CAddress(uint8_t address);
114 
118  void SetBankControl(uint8_t leds, EAddressType addressType = EAddressType::Normal);
119  void SetBankBrightness(uint8_t brightness, EAddressType addressType = EAddressType::Normal);
120  void SetBankColorA(uint8_t value, EAddressType addressType = EAddressType::Normal);
121  void SetBankColorB(uint8_t value, EAddressType addressType = EAddressType::Normal);
122  void SetBankColorC(uint8_t value, EAddressType addressType = EAddressType::Normal);
123  void SetBankColor(uint8_t red, uint8_t green, uint8_t blue, EAddressType addressType = EAddressType::Normal);
124 
128  void SetLEDBrightness(uint8_t led, uint8_t brighness, EAddressType addressType = EAddressType::Normal);
129  void SetOutputColor(uint8_t output, uint8_t value, EAddressType addressType = EAddressType::Normal);
130  void SetLEDColor(uint8_t led, uint8_t red, uint8_t green, uint8_t blue, EAddressType addressType = EAddressType::Normal);
131 
132 
136  void WriteRegister(uint8_t reg, uint8_t value, EAddressType addressType = EAddressType::Normal);
137  void ReadRegister(uint8_t reg, uint8_t *value);
138 
139  protected:
140 
141  private:
142  uint8_t _i2c_address;
143  uint8_t _i2c_address_broadcast = BROADCAST_ADDRESS;
144  uint8_t _enable_pin = 0xFF;
145  LED_Configuration _led_configuration = RGB;
146 
147  uint8_t getAddress(EAddressType addressType);
148 };
149 
150 #endif
MAX_CURRENT_25mA
@ MAX_CURRENT_25mA
Definition: LP50XX.h:39
RGB
@ RGB
Definition: LP50XX.h:21
LP50XX_Configuration
LP50XX_Configuration
Definition: LP50XX.h:36
LP50XX::SetBankColorB
void SetBankColorB(uint8_t value, EAddressType addressType=EAddressType::Normal)
Sets BANK color B related to Output 1,4,7,10.
Definition: LP50XX.cpp:302
Broadcast
@ Broadcast
Definition: LP50XX.h:53
PWM_DITHERING_ON
@ PWM_DITHERING_ON
Definition: LP50XX.h:42
BRG
@ BRG
Definition: LP50XX.h:26
DEFAULT_ADDRESS
#define DEFAULT_ADDRESS
Definition: LP50XX.h:17
POWER_SAVE_OFF
@ POWER_SAVE_OFF
Definition: LP50XX.h:45
LED_2
@ LED_2
Definition: LP50XX.h:32
LED_1
@ LED_1
Definition: LP50XX.h:31
LP50XX::SetPWMDithering
void SetPWMDithering(uint8_t dithering)
Sets the PWM dithering of the device.
Definition: LP50XX.cpp:183
LP50XX::SetGlobalLedOff
void SetGlobalLedOff(uint8_t value)
Turns all LED outputs ON or OFF.
Definition: LP50XX.cpp:219
LP50XX::SetBankBrightness
void SetBankBrightness(uint8_t brightness, EAddressType addressType=EAddressType::Normal)
Sets the brightness level of the whole BANK.
Definition: LP50XX.cpp:282
LP50XX::SetOutputColor
void SetOutputColor(uint8_t output, uint8_t value, EAddressType addressType=EAddressType::Normal)
Sets the color level of a single output.
Definition: LP50XX.cpp:386
POWER_SAVE_ON
@ POWER_SAVE_ON
Definition: LP50XX.h:46
BGR
@ BGR
Definition: LP50XX.h:23
LP50XX::SetBankColor
void SetBankColor(uint8_t red, uint8_t green, uint8_t blue, EAddressType addressType=EAddressType::Normal)
Sets the BANK color according to the set LED configuration SetLEDConfiguration.
Definition: LP50XX.cpp:324
LP50XX::SetPowerSaving
void SetPowerSaving(uint8_t powerSave)
Sets the power saving mode of the device.
Definition: LP50XX.cpp:147
BROADCAST_ADDRESS
#define BROADCAST_ADDRESS
Definition: LP50XX.h:18
EAddressType
EAddressType
Definition: LP50XX.h:51
GBR
@ GBR
Definition: LP50XX.h:25
LP50XX::ResetRegisters
void ResetRegisters(EAddressType addressType=EAddressType::Normal)
Resets the registers to their original values.
Definition: LP50XX.cpp:105
LP50XX::Configure
void Configure(uint8_t configuration, EAddressType addressType=EAddressType::Normal)
Configures the device according to the configuration param.
Definition: LP50XX.cpp:120
MAX_CURRENT_35mA
@ MAX_CURRENT_35mA
Definition: LP50XX.h:40
LP50XX::SetMaxCurrentOption
void SetMaxCurrentOption(uint8_t option)
Sets the max current option of the device.
Definition: LP50XX.cpp:201
LP50XX::Begin
void Begin(uint8_t i2c_address=DEFAULT_ADDRESS)
Initializes the I2C bus and the LP5009 or LP5012.
Definition: LP50XX.cpp:66
LP50XX
Class to communicate with the LP5009 or LP5012.
Definition: LP50XX.h:85
LED_GLOBAL_OFF
@ LED_GLOBAL_OFF
Definition: LP50XX.h:38
LED_3
@ LED_3
Definition: LP50XX.h:33
LP50XX::WriteRegister
void WriteRegister(uint8_t reg, uint8_t value, EAddressType addressType=EAddressType::Normal)
Writes a value to a specified register.
Definition: LP50XX.cpp:450
PWM_DITHERING_OFF
@ PWM_DITHERING_OFF
Definition: LP50XX.h:41
LP50XX::SetI2CAddress
void SetI2CAddress(uint8_t address)
Sets the I2C address.
Definition: LP50XX.cpp:257
LP50XX::SetAutoIncrement
void SetAutoIncrement(uint8_t autoInc)
Sets the auto increment mode of the device.
Definition: LP50XX.cpp:165
LP50XX::SetBankColorC
void SetBankColorC(uint8_t value, EAddressType addressType=EAddressType::Normal)
Sets BANK color C related to Output 2,5,8,11.
Definition: LP50XX.cpp:312
Normal
@ Normal
Definition: LP50XX.h:52
LP50XX::SetScaling
void SetScaling(uint8_t scaling)
Sets the PWM scaling used by the device.
Definition: LP50XX.cpp:129
LOG_SCALE_ON
@ LOG_SCALE_ON
Definition: LP50XX.h:48
LED_Configuration
LED_Configuration
Definition: LP50XX.h:20
GRB
@ GRB
Definition: LP50XX.h:22
LP50XX::ReadRegister
void ReadRegister(uint8_t reg, uint8_t *value)
Reads a value from a specified register.
Definition: LP50XX.cpp:460
LP50XX::Reset
void Reset()
Resets the device by using the enable pin if available and resetting the registers.
Definition: LP50XX.cpp:85
LED_0
@ LED_0
Definition: LP50XX.h:30
AUTO_INC_OFF
@ AUTO_INC_OFF
Definition: LP50XX.h:43
LP50XX::SetBankControl
void SetBankControl(uint8_t leds, EAddressType addressType=EAddressType::Normal)
Enables or Disables BANK control for specific LEDs.
Definition: LP50XX.cpp:272
LP50XX::SetLEDBrightness
void SetLEDBrightness(uint8_t led, uint8_t brighness, EAddressType addressType=EAddressType::Normal)
Sets the brightness level of a single LED (3 outputs)
Definition: LP50XX.cpp:375
AUTO_INC_ON
@ AUTO_INC_ON
Definition: LP50XX.h:44
LOG_SCALE_OFF
@ LOG_SCALE_OFF
Definition: LP50XX.h:47
LP50XX::LP50XX
LP50XX(void)
This function instantiates the class object.
Definition: LP50XX.cpp:19
LP50XX_LEDS
LP50XX_LEDS
Definition: LP50XX.h:29
LP50XX::SetLEDColor
void SetLEDColor(uint8_t led, uint8_t red, uint8_t green, uint8_t blue, EAddressType addressType=EAddressType::Normal)
Sets the LED color according to the set LED configuration SetLEDConfiguration.
Definition: LP50XX.cpp:399
LP50XX::SetLEDConfiguration
void SetLEDConfiguration(LED_Configuration ledConfiguration)
Sets the LED configuration acording the LED_Configuration enum.
Definition: LP50XX.cpp:248
LP50XX::SetBankColorA
void SetBankColorA(uint8_t value, EAddressType addressType=EAddressType::Normal)
Sets BANK color A related to Output 0,3,6,9.
Definition: LP50XX.cpp:292
LED_GLOBAL_ON
@ LED_GLOBAL_ON
Definition: LP50XX.h:37
LP50XX::SetEnablePin
void SetEnablePin(uint8_t enablePin)
Sets the enable pin of the device. This pin is used to enable the device in Begin.
Definition: LP50XX.cpp:238
RBG
@ RBG
Definition: LP50XX.h:24