Skip to content

Select desired illumination via an IR remote using either an HSB or RGB color model.

License

Notifications You must be signed in to change notification settings

dlpoole/RGB-LED-Strip-Controller

Repository files navigation

RGB-LED-Strip-Controller

Select desired illumination via an IR remote using either an HSB or RGB color model.

D.L. Poole

24 October 2022

This controller arose from unsuccessful attempts to purchase an off-the-shelf RGB LED Strip Controller that could reach a wide, fine-grained range of colors. It allows selecting or editing a desired illumination via an infrared remote using either a Hue/Saturation/Brightness (HSB) or Red/Green/Blue (RGB) color model interchangeably. The outputs were three 8-bit PWMs for MOSFETs or other LED drivers.

The original 2017 main used the FastLED CHSV object's hsv2rgb_rainbow color space which is based on linear ramps between primaries, but that had limitations in gamut using common 5030 LEDs. The yellow was dim, and at lower brightnesses, almost brownish. This branch uses the FastLED CHSV object's hsv2rgb_rainbow color space. HSV to RGB conversions and vice versa are implemented with code that implements the same slopes and intercepts since the FastLed library lacks a method for converting potentially edited RGB triplets back to HSV. For a fuller discussion, see https://github.com/FastLED/FastLED/wiki/Pixel-reference

image

This branch also adds three bits to the resolution of DIM and BRIGHT over and above the 8-bits of resolution per RGB primary. Each output can be blanked down to 1/8 timer interrupts so as to extend the dimming range to virtually extinguished before single steps cause hue and saturation shifts, as was evident in the original version in which the 8-bit analogWrite() was used alone. 8-bit resolution is sufficient for hue and saturation.

With reference to the accompanying remote keypad overlay, the Remote key functions are as follows:

  • HUE: Select or modify a hue, moving clockwise or counterclockwise around a color circle

  • BRIGHT: Raise total red+green+blue value without change of hue

  • DIM: Lower total red+green+blue value without change of hue

  • DESAT: Desaturate the selected hue towards white (center of the color circle)

  • RESAT: Resaturate towards a saturated primary or secondary (Red==0 || Green==0 || Blue==0)

  • RESET: Set a pure, saturated blue at 100% brightness (Blue = 255)

  • VARY: Start varying HUE around color circle or slow ongoing rate of variation by half

  • SAT: Return to the current hue, fully saturated at max brightness; cancel variable hue

  • +RED: Increase the Red component and adjust HSB accordingly

  • +GREEN: Increase the Green component and adjust HSB accordingly

  • +BLUE: Increase the Blue component and adjust HSB accordingly

  • -RED: Decrease the Red component and adjust HSB accordingly

  • -GREEN: Decrease the Green component and adjust HSB accordingly

  • -BLUE: Decrease the Blue component and adjust HSB accordingly

  • WARM: Simulate a tungsten bulb at max brightness

  • BRIGHT: Simulate a halogen bulb at max brightness

  • DAYLIGHT: Simulate a daylight source at max brightness

A single keypress performs a function or produces a single step in HUE, BRIGHTNESS, or SATURATION. Pressing, then holding a key for a half-second repeats the key’s function ten times per second. One can release the button at an appropriate value then jog forward or backward one step at a time to reach a final preference. Changes to HUE loop around the color circle indefinitely; when a brightness or saturation has reached a limit and further key presses can accomplish nothing, a blink occurs instead.

Edits to either HSB or RGB values are immediately transformed to the other model and output to the LEDs so one can freely move between color models. RGB edits to full ON (white) or full OFF leave hue undefined by the RGB values alone. At such endpoints, conversions to HSB preserve hue so that the user can resaturate a white back to its starting hue.

Color Models

Again with reference to the diagram on the remote overlay, the HSB color space lies around a unit circle of saturated primary (RGB) and secondary (CMY) hues along which hue is a floating point variable 0.0 <= hue <=1.0 Using a clock metaphor where saturated blue lies at 12:00, red at 4:00, and green at 8:00, the three primaries are linearly interpolated two at a time so that magenta lies at 2:00, yellow at 6:00, and cyan at 10:00. Along the hue circle, the SUM of RGB values (and the corresponding PWM outputs, red + green + blue equals 255, with one primary always zero.

RGB values are maintained as floats for ease of interpolation. They are rounded to the nearest integer before a write to the PWM pins, so they extinguish below bright = 1/254.5 = 0.004 and turn full ON above 254.5 Edits to red, green, blue, and brightness are performed in logarithmic steps rather than increments so as to produce visually similar steps at both ends of the range. The last few steps to blackout pass through some 8-bit underflow steps at which the LEDs don’t change.

Small hue changes in saturated colors are more readily perceived between red and green and less perceptible around blue. The choice of step size must be large enough to conveniently traverse the hue circle at a 10/sec repeat rate of a held key, yet small enough to appear continuous. This is accomplished by halving the step size between red and green.

The addition of any third primary desaturates a saturated hue towards white, which lies at the figurative center of the clock and at which hue is undefined. The radial dimension of any point in HSB space is represented by the floating point variable sat where 0.0 <= sat <=1.0 Thus, sat is 1.0 along the saturated hue circle and outside it and zero at its center.

Brightness is represented by the floating point variable 0.0 <= bright <=1.0 which is here defined as (red+green+blue)/255/3. Brightness is thus a constant 1/3 along the saturated hue circle. Reducing bright dims the display and extinguishes it as bright approaches zero. Brightness will “max out” a saturated primary at bright = 1/3, the two primaries of a secondary color at bright = 2/3, and the three primaries of a white at bright = 1. When any RGB component reaches 255, a further keypress will be ignored so as not to cause a hue shift, though a blink will occur to acknowledge it.

Although the polar coordinates of this HSB space suggests trigonometric definitions for the primaries around the hue circle, linear interpolation (triangular ramps) produced a much smoother range of hues.

Hardware

This controller consists of an Arduino UNO, a Vishay TSOP34438 IR Receiver, and an Adafruit Mini Remote Control (Product ID 389.) The original implementation was done on a stacked protoboard with the IR receive, three power MOSFETS, and terminal blocks for +12V input and the LED outputs. The MOSFETS were salvaged from one of the unsuccessful attempts to purchase an off-the-shelf controller, but were sufficient to drive the six feet of LED strip needed with 5V gate drive directly from the UNO pins. A scratch implementation might be done with the International Rectifier IRLIZ44NPBF N-channel power MOSFET. These FETs should be good to about 8 Amperes per channel at 100% ON without a heat sink or higher voltage gate driver, however, this author hasn’t actually tried that configuration, so YOYO and YRMV.

The Hardware connections are as follows:

  • D2: Input from Vishay TSOP34438 38KHz IR Receiver

  • PWM 9: Red PWM Pin; High = ON

  • PWM 10: Green PWM Pin; High = ON

  • PWM 11: Blue PWM Pin; High = ON

The sketch requires the IRLib2 library which can be downloaded from https://github.com/cyborg5/IRLib2 For the Vishay TSOP34438 IR Receiver and Adafruit Mini Remote Control (Product ID 389,) which generates NEC codes at 38KHz, decoding was most reliable using the library’s IRrecvPCI receiver with the enableAutoResume method and markExcess = 0 Use of the PCI receiver also avoids conflict with the PWM on pin D11 for TIMER2.

Remote Key Assignments are tabulated constants for the NEC key codes of the Adafruit Mini Remote. The table can be modified for other codes or remotes, though a change to the repeat logic may be necessary.

A keypad overlay for the Mini Remote is available in the GitHub Repo in several formats. If printed at scale on self adhesive (label) paper, the overlay can be optionally laminated with clear polyester tape then applied over the face of the Adafruit Mini Remote.

The Variable Hue key begins continuous cycling the hue at the then-current brightness and saturation. Subsequent keypresses slow the cycling by a factor of two. The hue can be dimmed, brightened, desaturated, or resaturated while cycling; the SAT key or any RGB edit stops the cycling at the then-current hue.


End-of-Document

About

Select desired illumination via an IR remote using either an HSB or RGB color model.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages