An Arduino library for HD108 LED strips. It drives HD108 LEDs over SPI with 16 bits per color channel and the chip's 5-bit global brightness, and adds helpers for HSV colors, gamma correction, rotating the strip and a low-power mode.
- Download HD108_Library.zip.
- Add it to your project:
- Arduino: Place the downloaded library in the
librariesfolder of your Arduino sketchbook. - PlatformIO: Add the library to your
libdirectory or use the Library Manager to include it in your project.
- Arduino: Place the downloaded library in the
- Wire the strip's data and clock inputs to your board's SPI data (MOSI) and clock (SCK) pins.
- Light the first LED:
#include <HD108_Library.h>
HD108 strip(60); // number of LEDs on the strip
void setup() {
strip.begin();
strip.setBrightness(31, 31, 31); // global brightness per channel, 0 to 31
strip.setPixelColor8Bit(0, 255, 0, 0); // first LED red
strip.show();
}
void loop() {}More sketches are in examples/.
I developed the HD108 LED Library because there were no well-functioning or well-documented libraries available. Additionally, the HD108 datasheet lacked clear instructions on how to operate and control the LEDs. This library aims to fill that gap, providing an easy-to-use, well-documented solution for controlling HD108 LED chips.
Here’s a simple example to get you started with the HD108 LED Library:
#include <HD108_Library.h>
HD108 strip(252);
uint16_t colorIndex = 0;
void setup() {
strip.begin();
strip.setBrightness(31, 31, 31); // Max brightness
strip.setSPISpeed(4000000); // ~4799999 Bits
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
uint8_t r, g, b;
if (WheelPos < 85) {
r = 255 - WheelPos * 3;
g = 0;
b = WheelPos * 3;
} else if (WheelPos < 170) {
WheelPos -= 85;
r = 0;
g = WheelPos * 3;
b = 255 - WheelPos * 3;
} else {
WheelPos -= 170;
r = WheelPos * 3;
g = 255 - WheelPos * 3;
b = 0;
}
return (r << 16) | (g << 8) | b;
}
void loop() {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
uint16_t pos = (i + colorIndex) % 256;
uint32_t color = Wheel(pos);
uint8_t r = (color & 0xFF0000) >> 16;
uint8_t g = (color & 0x00FF00) >> 8;
uint8_t b = (color & 0x0000FF);
strip.setPixelColor8Bit(i, r, g, b);
}
strip.show();
colorIndex = (colorIndex + 1) % 256;
}- Luis Blüml
Mozilla Public License 2.0, see LICENSE.
You can download the HD108 LED Library by clicking the link below: