Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rainbow effects more colorful #3681

Open
wants to merge 4 commits into
base: 0_15
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 27 additions & 9 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,20 +1022,38 @@ void Segment::blur(uint8_t blur_amount) {
/*
* Put a value 0 to 255 in to get a color value.
* The colours are a transition r -> g -> b -> back to r
* Inspired by the Adafruit examples.
*/
uint32_t Segment::color_wheel(uint8_t pos) {
if (palette) return color_from_palette(pos, false, true, 0);
uint8_t w = W(currentColor(0));
pos = 255 - pos;
if (pos < 85) {
return RGBW32((255 - pos * 3), 0, (pos * 3), w);
} else if(pos < 170) {
pos -= 85;
return RGBW32(0, (pos * 3), (255 - pos * 3), w);
if (useAltWheel) {
// by @TripleWhy https://github.com/Aircoookie/WLED/pull/3681 (https://github.com/TripleWhy)
// Rotates the color in HSV space, where pos is H. (0=0deg, 256=360deg)
// These h and f values are the same h and f you have in the regular HSV to RGB conversion.
// The whole funciton really is just a HSV conversion, but assuming H=pos, S=1 and V=1.
const uint32_t h = (pos * 3) / 128;
const uint32_t f = (pos * 6) % 256;
switch (h) {
case 0: return RGBW32(255 , f , 0 , w);
case 1: return RGBW32(255 - f, 255 , 0 , w);
case 2: return RGBW32(0 , 255 , f , w);
case 3: return RGBW32(0 , 255 - f, 255 , w);
case 4: return RGBW32(f , 0 , 255 , w);
case 5: return RGBW32(255 , 0 , 255 - f, w);
default: return 0;
}
} else {
pos -= 170;
return RGBW32((pos * 3), (255 - pos * 3), 0, w);
// Inspired by the Adafruit examples.
pos = 255 - pos;
if (pos < 85) {
return RGBW32((255 - pos * 3), 0, (pos * 3), w);
} else if(pos < 170) {
pos -= 85;
return RGBW32(0, (pos * 3), (255 - pos * 3), w);
} else {
pos -= 170;
return RGBW32((pos * 3), (255 - pos * 3), 0, w);
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions wled00/cfg.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (serialBaud < 96 || serialBaud > 15000) serialBaud = 1152;
updateBaudRate(serialBaud *100);

JsonArray hw_if_i2c = hw[F("if")][F("i2c-pin")];
JsonArray hw_if_i2c = hw["if"][F("i2c-pin")];
CJSON(i2c_sda, hw_if_i2c[0]);
CJSON(i2c_scl, hw_if_i2c[1]);
PinManagerPinType i2c[2] = { { i2c_sda, true }, { i2c_scl, true } };
Expand All @@ -330,7 +330,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
i2c_sda = -1;
i2c_scl = -1;
}
JsonArray hw_if_spi = hw[F("if")][F("spi-pin")];
JsonArray hw_if_spi = hw["if"][F("spi-pin")];
CJSON(spi_mosi, hw_if_spi[0]);
CJSON(spi_sclk, hw_if_spi[1]);
CJSON(spi_miso, hw_if_spi[2]);
Expand All @@ -353,6 +353,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(briMultiplier, light[F("scale-bri")]);
CJSON(strip.paletteBlend, light[F("pal-mode")]);
CJSON(autoSegments, light[F("aseg")]);
CJSON(useAltWheel, light[F("alt-wheel")]);

CJSON(gammaCorrectVal, light["gc"]["val"]); // default 2.8
float light_gc_bri = light["gc"]["bri"];
Expand Down Expand Up @@ -821,7 +822,7 @@ void serializeConfig() {

hw[F("baud")] = serialBaud;

JsonObject hw_if = hw.createNestedObject(F("if"));
JsonObject hw_if = hw.createNestedObject("if");
JsonArray hw_if_i2c = hw_if.createNestedArray("i2c-pin");
hw_if_i2c.add(i2c_sda);
hw_if_i2c.add(i2c_scl);
Expand All @@ -837,6 +838,7 @@ void serializeConfig() {
light[F("scale-bri")] = briMultiplier;
light[F("pal-mode")] = strip.paletteBlend;
light[F("aseg")] = autoSegments;
light[F("alt-wheel")] = useAltWheel;

JsonObject light_gc = light.createNestedObject("gc");
light_gc["bri"] = (gammaCorrectBri) ? gammaCorrectVal : 1.0f; // keep compatibility
Expand Down
10 changes: 5 additions & 5 deletions wled00/colors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ void setRandomColor(byte* rgb)

void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb
{
float h = ((float)hue)/65535.0f;
float h = ((float)hue)/10922.5f; // hue*6/65535
float s = ((float)sat)/255.0f;
int i = floorf(h*6);
float f = h * 6.0f - i;
int i = int(h);
float f = h - i;
int p = int(255.0f * (1.0f-s));
int q = int(255.0f * (1.0f-f*s));
int t = int(255.0f * (1.0f-(1.0f-f)*s));
int q = int(255.0f * (1.0f-s*f));
int t = int(255.0f * (1.0f-s*(1.0f-f)));
p = constrain(p, 0, 255);
q = constrain(q, 0, 255);
t = constrain(t, 0, 255);
Expand Down
1 change: 1 addition & 0 deletions wled00/data/settings_leds.htm
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ <h3>Advanced</h3>
<option value="2">Linear (never wrap)</option>
<option value="3">None (not recommended)</option>
</select><br>
Alt color wheel: <input type="checkbox" name="ACW"><br>
Target refresh rate: <input type="number" class="s" min="1" max="120" name="FR" required> FPS
<hr class="sml">
<div id="cfg">Config template: <input type="file" name="data2" accept=".json"><button type="button" class="sml" onclick="loadCfg(d.Sf.data2)">Apply</button><br></div>
Expand Down
1 change: 1 addition & 0 deletions wled00/set.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
strip.paletteFade = request->hasArg(F("PF"));
t = request->arg(F("TP")).toInt();
randomPaletteChangeTime = MIN(255,MAX(1,t));
useAltWheel = request->hasArg(F("ACW"));

nightlightTargetBri = request->arg(F("TB")).toInt();
t = request->arg(F("TL")).toInt();
Expand Down
1 change: 1 addition & 0 deletions wled00/wled.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ WLED_GLOBAL bool cctFromRgb _INIT(false); // CCT is calculated from RGB
WLED_GLOBAL bool gammaCorrectCol _INIT(true); // use gamma correction on colors
WLED_GLOBAL bool gammaCorrectBri _INIT(false); // use gamma correction on brightness
WLED_GLOBAL float gammaCorrectVal _INIT(2.8f); // gamma correction value
WLED_GLOBAL bool useAltWheel _INIT(false); // alternate method for calculating Segment::color_wheel()

WLED_GLOBAL byte col[] _INIT_N(({ 255, 160, 0, 0 })); // current RGB(W) primary color. col[] should be updated if you want to change the color.
WLED_GLOBAL byte colSec[] _INIT_N(({ 0, 0, 0, 0 })); // current RGB(W) secondary color
Expand Down
1 change: 1 addition & 0 deletions wled00/xml.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',SET_F("IR"),irPin);
sappend('v',SET_F("IT"),irEnabled);
sappend('c',SET_F("MSO"),!irApplyToAllSelected);
sappend('c',SET_F("ACW"),useAltWheel);
}

if (subPage == SUBPAGE_UI)
Expand Down