Difference between revisions of "LED Control with LPD8806 Library + Arduino"
m (Ethanshry moved page Using Arduino LPD8806 Library to LED Control with LPD8806 Library + Arduino: Fall 2018 Wiki Reworks)
|(One intermediate revision by the same user not shown)|
|Line 43:||Line 43:|
Latest revision as of 16:03, 18 August 2018
The LPD8806 library is used to control LPD8806/LPD8803/LPD8809 PWM LED driver chips, strips and pixels. The link for downloading and instructions for installing the library can be found here. 
Creating an instance of the LPD8806 class
The LPD8806 library has three constructors:
LPD8806(uint16_t n, uint8_t dpin, uint8_t cpin)
This constructor takes in the number of LEDs in the strip, the data pin (port on arduino connected to DI), and the clock pin (port on arduino connected to CI).
LPD8806 strip1 = LPD8806(48, 51, 52)//creates an LPD8806 object to control 48 lights, with data pin on 51, and clock pin on 52
This constructor takes in the number of LEDs to control, and relies on the Arduino's hardware SPI. These pins vary for each Arduino, so make sure you have it connected to the right pins.
LPD8806 strip2 = LPD8806(48)//creates an LPD8806 object with Arduino SPI pins, (ie, on the Arduino Mega, these pins are 51 for the data pin and 52 for the clock pin)
This is a blank constructor, you must set the number of LEDs, data and clock pin separately using
updatePins(uint8_t dpin, uint8_t cpin),
updatePins() (for hardware SPI), and
LPD8806 strip3 = new LPD8806(); //create LPD8806 object strip3.updatePins(51,52); //set data pin to 51, clock pin to 52 strip3.updateLength(48); //set length to 48
Writing to the LED strips
You can write to the LED strips using
setPixelColor() and display the lights using
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
This method takes in the the LED you want to write to (int between 0 to numLEDs-1, 0 is the first light on the strip), and the color you want to represent using three 7-bit r,g,b components
Alternatively, you can use
setPixelColor(uint16_t n, uint32_t c), which takes in 32 bit GRB value instead. Entering in 0 as the GRB value will turn the LED off.
strip1.setPixelColor(0,255,0,0); //set first LED on strip to red strip1.setPixelColor(1,255); //set second LED on strip to blue strip1.show() //display lights, you should see the first light turn red, and the second blue without delay.