achimpieters/esp32-color-converter

1.0.1

Latest
uploaded 4 days ago
HomeKit-compatible HSB and Color Temperature (mired) to RGBW conversion library for ESP32

readme

# Example for color-converter Component

## What it Does

This example demonstrates how to convert HomeKit-compatible color values into RGBW values using the ESP-IDF framework. It supports both HSB (Hue, Saturation, Brightness) and color temperature (in mireds), producing 8-bit RGBW outputs suitable for NeoPixels or PWM-controlled LED drivers.

This component does **not** drive LED's directly, but provides the conversion logic needed for your driver implementation.

## Configuration

There is no `menuconfig` configuration required. The component simply exposes two functions:

- `hsb2rgbw(hue, saturation, brightness, rgbw_out)`
- `mired2rgbw(mired, brightness, rgbw_out)`

## Default Behavior

| Setting             | Description                                              | Example     |
|--------------------|----------------------------------------------------------|-------------|
| Hue                | Color hue in degrees (0–360)                             | 180 (Cyan)  |
| Saturation         | Color saturation from 0.0 to 1.0                         | 1.0         |
| Brightness         | Overall brightness from 0.0 to 1.0                       | 1.0         |
| Mired              | Color temperature (1000000 / Kelvin)                     | 370 (≈2700K)|

## Example Code

Here’s how to use the component to convert color inputs:

```c
#include <stdio.h>
#include "color_converter.h"

void app_main(void)
{
    int rgbw[4];

    // Convert HSB to RGBW
    hsb2rgbw(180.0f, 1.0f, 1.0f, rgbw); // Cyan
    printf("RGBW from HSB: R=%d, G=%d, B=%d, W=%d\n", rgbw[0], rgbw[1], rgbw[2], rgbw[3]);

    // Convert Color Temperature to RGBW
    mired2rgbw(370, 1.0f, rgbw); // ≈2700K (warm white)
    printf("RGBW from Mired: R=%d, G=%d, B=%d, W=%d\n", rgbw[0], rgbw[1], rgbw[2], rgbw[3]);
}
```

## Building and Running

Build the project:
```bash
idf.py build
```

Flash it to the ESP32:
```bash
idf.py flash
```

Monitor logs:
```bash
idf.py monitor
```

## Example Output

```
RGBW from HSB: R=0, G=255, B=255, W=0
RGBW from Mired: R=0, G=0, B=0, W=255
```

## Notes

- This component works on all ESP32 variants (ESP32, C3, S2, S3, C6).
- It is hardware-agnostic; you must implement your own LED driver logic.
- Ideal for NeoPixel, RGBW LED strips, or CW/WW white LED's.
- Accurate white mixing using the lowest RGB component as shared white.

---

StudioPieters® | Innovation and Learning Labs | https://www.studiopieters.nl

Links

Maintainer

  • info@studiopieters.nl

License: MIT

To add this component to your project, run:

idf.py add-dependency "achimpieters/esp32-color-converter^1.0.1"

or download archive

Stats

  • Archive size
    Archive size ~ 6.21 KB
  • Downloaded in total
    Downloaded in total 6 times
  • Downloaded this version
    This version: 5 times

Badge

achimpieters/esp32-color-converter version: 1.0.1
|