Skip to content

Commit 8764e66

Browse files
committed
The routine setColorHSB() was incorrect. It implemented the HSL color space and not the HSL one.
Refactored the routines so that it reflects the HSL space. See [Wrong HSB Format](#3).
1 parent 6b26978 commit 8764e66

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

ChainableLED.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,23 @@ void ChainableLED::setColorRGB(byte led, byte red, byte green, byte blue)
131131
sendByte(0x00);
132132
}
133133

134-
void ChainableLED::setColorHSB(byte led, float hue, float saturation, float brightness)
134+
void ChainableLED::setColorHSL(byte led, float hue, float saturation, float lightness)
135135
{
136136
float r, g, b;
137137

138138
constrain(hue, 0.0, 1.0);
139139
constrain(saturation, 0.0, 1.0);
140-
constrain(brightness, 0.0, 1.0);
140+
constrain(lightness, 0.0, 1.0);
141141

142142
if(saturation == 0.0)
143143
{
144-
r = g = b = brightness;
144+
r = g = b = lightness;
145145
}
146146
else
147147
{
148-
float q = brightness < 0.5 ?
149-
brightness * (1.0 + saturation) : brightness + saturation - brightness * saturation;
150-
float p = 2.0 * brightness - q;
148+
float q = lightness < 0.5 ?
149+
lightness * (1.0 + saturation) : lightness + saturation - lightness * saturation;
150+
float p = 2.0 * lightness - q;
151151
r = hue2rgb(p, q, hue + 1.0/3.0);
152152
g = hue2rgb(p, q, hue);
153153
b = hue2rgb(p, q, hue - 1.0/3.0);

ChainableLED.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ChainableLED
5151

5252
void init();
5353
void setColorRGB(byte led, byte red, byte green, byte blue);
54-
void setColorHSB(byte led, float hue, float saturation, float brightness);
54+
void setColorHSL(byte led, float hue, float saturation, float lightness);
5555

5656
private:
5757
byte _clk_pin;

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ChainableLED
33

44
Arduino library compatible with Grove Chainable LED and the P9813 chip. It allows controlling a chain of LEDS individually.
55

6-
Supports both RGB and HSB color spaces for setting the color of each individual LED.
6+
Supports both RGB and HSL color spaces for setting the color of each individual LED.
77

88
Compatible with [Particle devices](https://www.particle.io/).
99

@@ -29,6 +29,6 @@ public:
2929

3030
void init();
3131
void setColorRGB(byte led, byte red, byte green, byte blue);
32-
void setColorHSB(byte led, float hue, float saturation, float brightness);
32+
void setColorHSL(byte led, float hue, float saturation, float lightness);
3333
}
3434
```

examples/CycleThroughColors/CycleThroughColors.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
* Example of using the ChainableRGB library for controlling a Grove RGB.
4-
* This code cycles through all the colors in an uniform way. This is accomplished using a HSB color space.
4+
* This code cycles through all the colors in an uniform way. This is accomplished using a HSL color space.
55
*/
66

77

@@ -22,7 +22,7 @@ boolean up = true;
2222
void loop()
2323
{
2424
for (byte i=0; i<NUM_LEDS; i++)
25-
leds.setColorHSB(i, hue, 1.0, 0.5);
25+
leds.setColorHSL(i, hue, 1.0, 0.5);
2626

2727
delay(50);
2828

keywords.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#######################################
2-
# Syntax Coloring Map For Ultrasound
2+
# Syntax Coloring Map For ChainnableLED
33
#######################################
44

55
#######################################
@@ -12,7 +12,7 @@ ChainableLED KEYWORD1
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
1414
setColorRGB KEYWORD2
15-
setColorHSB KEYWORD2
15+
setColorHSL KEYWORD2
1616

1717
#######################################
1818
# Constants (LITERAL1)

0 commit comments

Comments
 (0)