Skip to content

Commit

Permalink
Change 2D Centerbars: add vertical centering and vertical coloring
Browse files Browse the repository at this point in the history
Sound settings: add helper texts in italic

Change 2D Centerbars: add vertical centering and vertical coloring. Add effect controls for horizontal /vertical centering and vertical coloring: see #190
- change GEW_base in FX.h and FX.cpp

Custom effects: place download message on separate line
  • Loading branch information
ewoudwijma committed Apr 7, 2022
1 parent 04ea75d commit 71c1cd9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
45 changes: 30 additions & 15 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6406,17 +6406,21 @@ uint16_t WS2812FX::mode_waterfall(void) { // Waterfall. By: An
// ** 2D GEQ //
/////////////////////////

uint16_t WS2812FX::GEQ_base(bool centered) { // By Will Tatam. Refactor by Ewoud Wijma.
uint16_t WS2812FX::GEQ_base(int NUMB_BANDS, bool centered_horizontal, bool centered_vertical, bool color_vertical) { // By Will Tatam. Refactor by Ewoud Wijma.

// centered_vertical = true;
// color_vertical = true;

fadeToBlackBy(leds, SEGMENT.speed);

int NUMB_BANDS = map(SEGMENT.custom1, 0, 255, 1, 16);
int barWidth = (SEGMENT.width / NUMB_BANDS);
int barWidth = SEGMENT.width / NUMB_BANDS;
if (centered_vertical)
barWidth /= 2;
int bandInc = 1;
if(barWidth == 0) {
// Matrix narrower than fft bands
barWidth = 1;
bandInc = (NUMB_BANDS / SEGMENT.width);
bandInc = NUMB_BANDS / SEGMENT.width;
}
bool rippleTime;
if (millis() - SEGENV.step >= 255 - SEGMENT.intensity)
Expand All @@ -6432,29 +6436,40 @@ uint16_t WS2812FX::GEQ_base(bool centered) { // By Will Tata
int b = 0;
for (int band = 0; band < NUMB_BANDS; band += bandInc) {
int barHeight = map(fftResult[band], 0, 255, 0, SEGMENT.height);
if ((barHeight % 2 == 1) && centered) barHeight++; //get an even barHeight if centered
int yStartBar = centered?(SEGMENT.height - barHeight) / 2:0; //lift up the bar if centered
int yStartPeak = centered?(SEGMENT.height - previousBarHeight[band]) / 2:0; //lift up the peaks if centered
if ((barHeight % 2 == 1) && centered_horizontal) barHeight++; //get an even barHeight if centered_horizontal
int yStartBar = centered_horizontal?(SEGMENT.height - barHeight) / 2:0; //lift up the bar if centered_horizontal
int yStartPeak = centered_horizontal?(SEGMENT.height - previousBarHeight[band]) / 2:0; //lift up the peaks if centered_horizontal

for (int w = 0; w < barWidth; w++) {
int x = (barWidth * b) + w;
for (int y=0; y<SEGMENT.height; y++)
{
CRGB color = CRGB::Black; //if not part of bars or peak, make black (not fade to black)

//bar
if (y>=yStartBar && y<yStartBar + barHeight)
color = color_from_palette((band * 35), false, PALETTE_SOLID_WRAP, 0);
if (y >= yStartBar && y < yStartBar + barHeight) {
if (color_vertical)
color = color_from_palette(map(y, 0, SEGMENT.height - 1, 0, 255), false, PALETTE_SOLID_WRAP, 0);
else
color = color_from_palette(band * 35, false, PALETTE_SOLID_WRAP, 0);
}

//low and high peak (must exist && on peak position && only below if centered effect)
if ((previousBarHeight[band] > 0) && (SEGMENT.intensity < 255) && (y==yStartPeak || y==yStartPeak + previousBarHeight[band]-1) && (centered || y!=yStartPeak))
//low and high peak (must exist && on peak position && only below if centered_horizontal effect)
if ((previousBarHeight[band] > 0) && (SEGMENT.intensity < 255) && (y==yStartPeak || y==yStartPeak + previousBarHeight[band]-1) && (centered_horizontal || y!=yStartPeak))
color = SEGCOLOR(2)==CRGB::Black?color_from_palette((band * 35), false, PALETTE_SOLID_WRAP, 0):SEGCOLOR(2); //low peak

leds[XY(x, SEGMENT.height - 1 - y)] = color;
if (centered_vertical) {
leds[XY(SEGMENT.width / 2 - 1 + x, SEGMENT.height - 1 - y)] = color;
leds[XY(SEGMENT.width / 2 - 1 - x, SEGMENT.height - 1 - y)] = color;
}
else {
leds[XY(x, SEGMENT.height - 1 - y)] = color;
}
}
} //barWidth
b++;

if (rippleTime) previousBarHeight[band]-=centered?2:1; //delay/ripple effect
if (rippleTime) previousBarHeight[band]-=centered_horizontal?2:1; //delay/ripple effect
if (barHeight > previousBarHeight[band]) previousBarHeight[band] = barHeight; //drive the peak up
}

Expand All @@ -6463,7 +6478,7 @@ uint16_t WS2812FX::GEQ_base(bool centered) { // By Will Tata
} //GEQ_base

uint16_t WS2812FX::mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma.
return GEQ_base(false);
return GEQ_base(map(SEGMENT.custom1, 0, 255, 1, 16), false, false, false);
} // mode_2DGEQ()


Expand All @@ -6472,7 +6487,7 @@ uint16_t WS2812FX::mode_2DGEQ(void) { // By Will Tatam. Code
/////////////////////////

uint16_t WS2812FX::mode_2DCenterBars(void) { // Written by Scott Marley Adapted by Spiro-C..
return GEQ_base(true);
return GEQ_base(16, SEGMENT.custom1 > 128, SEGMENT.custom2 > 128, SEGMENT.custom3 > 128);
} // mode_2DCenterBars()


Expand Down
4 changes: 2 additions & 2 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ class WS2812FX {
// mode_2DCAElementary(void);

uint16_t
GEQ_base(bool); //private???
GEQ_base(int, bool, bool, bool); //private???

uint16_t
_lengthRaw; //private? not in AC (anymore)
Expand Down Expand Up @@ -1432,7 +1432,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
" ♫ Gravfreq@Rate of fall,Sensivity;,!;!",
" ♫ DJ Light@Speed;;",
" ♫ 2D Funky Plank@Scroll speed,,# of bands;;",
" ♫ 2D CenterBars@Bar speed,Ripple decay,# of bands;,,Peak Color;!",
" ♫ 2D CenterBars@Bar speed,Ripple decay,Center ↔ ☑,Center ↕ ☑, Color ↕ ☑;,,Peak Color;!",
"2D Pulser@Speed,Blur;;!",
" ♫ Blurz@Fade rate,Blur amount;,Color mix;!",
"2D Drift@Rotation speed,Blur amount;;!",
Expand Down
9 changes: 6 additions & 3 deletions wled00/data/settings_sound.htm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
<h2>Sound Input Settings</h2>
Squelch: <input name="SQ" type="number" min="0" max="255" required><br>
Gain: <input name="GN" type="number" min="0" max="255" required><br>
AGC: <input type="checkbox" name="AGC"><br>
<i>Enter values between 0 and 255. To tune, start with Squelch=10 and Gain=40 and modify according to your setup</i><br>
Automatic Gain Control (AGC): <input type="checkbox" name="AGC"><br>
<i>AGC is an expiremental feature</i><br>
<h2>Sound Input Pin Manager</h2>
Microphone type: <select id="dme" name="DMM" onchange="enDM()" >
<option value="0" selected>Generic Analog</option>
Expand All @@ -47,11 +49,12 @@ <h2>Sound Input Pin Manager</h2>
<option value="4">Generic I2S with Mclk</option>
<option value="5">Generic I2S PDM</option>
</select><br>
<div id="dm">
<div id="dm">
I2S SD pin: <input type="number" min="-1" max="40" name="DI"><br>
I2S WS pin: <input type="number" min="-1" max="40" name="LR"><br>
I2S SCK pin: <input type="number" min="-1" max="40" name="CK"><br>
</div>
</div>
<i>Changing the microphone type or pins requires a hard reset/power cycle</i><br>
<div id="am">
Analog Input pin: <input type="number" min="-1" max="40" name="SI"><br>
</div>
Expand Down
23 changes: 13 additions & 10 deletions wled00/html_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,22 @@ var d=document;function H(){window.open("https://github.com/atuline/WLED/wiki/Sq
onclick="H()">?</button></div><button type="button" onclick="B()">Back</button>
<button type="submit">Save</button><hr><h2>Sound Input Settings</h2>Squelch:
<input name="SQ" type="number" min="0" max="255" required><br>Gain: <input
name="GN" type="number" min="0" max="255" required><br>AGC: <input
type="checkbox" name="AGC"><br><h2>Sound Input Pin Manager</h2>Microphone type:
<select id="dme" name="DMM" onchange="enDM()"><option value="0"
selected="selected">Generic Analog</option><option value="1">Generic I2S
</option><option value="2">ES7243</option><option value="3">SPH0654</option>
<option value="4">Generic I2S with Mclk</option><option value="5">
name="GN" type="number" min="0" max="255" required><br><i>
Enter values between 0 and 255. To tune, start with Squelch=10 and Gain=40 and modify according to your setup
</i><br>Automatic Gain Control (AGC): <input type="checkbox" name="AGC"><br><i>
AGC is an expiremental feature</i><br><h2>Sound Input Pin Manager</h2>
Microphone type: <select id="dme" name="DMM" onchange="enDM()"><option
value="0" selected="selected">Generic Analog</option><option value="1">
Generic I2S</option><option value="2">ES7243</option><option value="3">SPH0654
</option><option value="4">Generic I2S with Mclk</option><option value="5">
Generic I2S PDM</option></select><br><div id="dm">I2S SD pin: <input
type="number" min="-1" max="40" name="DI"><br>I2S WS pin: <input type="number"
min="-1" max="40" name="LR"><br>I2S SCK pin: <input type="number" min="-1"
max="40" name="CK"><br></div><div id="am">Analog Input pin: <input
type="number" min="-1" max="40" name="SI"><br></div><button type="button"
onclick="B()">Back</button><button type="submit">Save</button></form></body>
</html>)=====";
max="40" name="CK"><br></div><i>
Changing the microphone type or pins requires a hard reset/power cycle</i><br>
<div id="am">Analog Input pin: <input type="number" min="-1" max="40" name="SI">
<br></div><button type="button" onclick="B()">Back</button><button
type="submit">Save</button></form></body></html>)=====";


#ifdef WLED_ENABLE_DMX
Expand Down
2 changes: 1 addition & 1 deletion wled00/src/dependencies/arti/arti.h
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ class ARTI {
const char * version = metaData["version"];
if (strcmp(version, "0.3.0") != 0)
{
ERROR_ARTI("Version of definition.json file (%s) should be 0.3.0. Press Download wled.json\n", version);
ERROR_ARTI("Version of definition.json file (%s) should be 0.3.0.\nPress Download wled.json\n", version);
return false;
}
const char * startNode = metaData["start"];
Expand Down

0 comments on commit 71c1cd9

Please sign in to comment.