Skip to content

About

Arduino library for HD108 LEDs over SPI: 16 bits per color channel, 5-bit global brightness, HSV, gamma correction and rotation helpers.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

HD108 Library: drive HD108 LEDs with 16 bits per channel

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.

What show() sends over SPI: a start frame of 64 zero bits, then per LED a 16-bit header with a start bit and 5-bit gain for red, green and blue, followed by 16 bits each for red, green and blue, and an end frame of (n/16 + 1) words of 0xFFFF

Quick start

  1. Download HD108_Library.zip.
  2. Add it to your project:
    • Arduino: Place the downloaded library in the libraries folder of your Arduino sketchbook.
    • PlatformIO: Add the library to your lib directory or use the Library Manager to include it in your project.
  3. Wire the strip's data and clock inputs to your board's SPI data (MOSI) and clock (SCK) pins.
  4. 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/.

Why it exists

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.

Example

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;
}

Author

  • Luis Blüml

License

Mozilla Public License 2.0, see LICENSE.


Download

You can download the HD108 LED Library by clicking the link below:

Download HD108 LED Library

About

Arduino library for HD108 LEDs over SPI: 16 bits per color channel, 5-bit global brightness, HSV, gamma correction and rotation helpers.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages