LP55231 Breakout Board Hookup Guide
Contributors:
Byron J.
Simple Example
We'll start with a simple example: initializing the IC, and turning the LED channels on and off.
language:c
/******************************************************************************
simple-demo.ino
simple demo of using LP55231 to control 9 LEDs.
Byron Jacquot @ SparkFun Electronics
October 12, 2016
https://github.com/sparkfun/SparkFun_LP55231_Arduino_Library
The simplest demo of LP55231 functionality. Initializes the chip, then
sequentially turn on each of the 9 channels.
Resources:
Development environment specifics:
Written using Arduino 1.6.5
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
Please review the LICENSE.md file included with this example. If you have any questions
or concerns with licensing, please contact techsupport@sparkfun.com.
Distributed as-is; no warranty is given.
******************************************************************************/
#include <Wire.h>
#include <lp55231.h>
Lp55231 ledChip;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(5000);
Serial.println("-- Starting Setup() --");
ledChip.Begin();
ledChip.Enable();
delay(500);
Serial.println("-- Setup() Complete --");
}
void loop() {
// put your main code here, to run repeatedly:
// current will track the LED we're turning on
// previous will keep track of the last one we turned on to turn it off again
static uint8_t current = 0, previous = 0;
static uint32_t next = millis()+1000;
if(millis() >= next)
{
next += 1000;
Serial.print("Illuminating: ");
Serial.println(current);
ledChip.SetChannelPWM(previous, 0);
ledChip.SetChannelPWM(current, 255);
previous = current;
current++;
if(current >= ledChip.NumChannels)
{
current = 0;
}
}
}
The Lp55231 class is declared with no parameters, initializing it to the default I2C address of 0x32. Begin
initializes the I2C bus, and Enable
turns on the LED driver stages.
As loop
runs, it cycles among the outputs, calling SetChannnelPWM
on each channel in turn, to turn it on, wait for a moment, then turn it off and proceeed to the next channel.
The result of the program is that each LED lights successively: blue one, green one, blue two, green two, blue three, green there, then each of the red channels.
Other Examples
There are a couple other demos of the simple Lp55231
library in the repository.
- simple-two-chips demonstrates two LP55231 breakouts on the I2C bus, each configured for a unique address. There is a note in the file describing how the breakout boardss need to be configured for the example.
- simple-master-fader demonstrates the color mixing capabilities of the IC. The output channels are set to a color ratio using their
SetChannelPWM
methods, and also assigned to the same master fader usingAssignChannelToMasterFader
. Asloop
executes, it adjusts the group usingSetMasterFader
. The color ratios established in setup are maintained as the master fader value is adjusted.