Skip to content

Commit 6f916e2

Browse files
allow to configure palette
1 parent c736efb commit 6f916e2

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

fastled_patterns/BlendWave.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@
1010
BlendWave::BlendWave(CRGB* neopixels, uint16_t numLEDS) {
1111
_neopixels = neopixels;
1212
_numLEDS = numLEDS;
13-
14-
currentPalette = OceanColors_p;
1513
}
1614

17-
void BlendWave::loop() {
18-
int thisPhase = beatsin8(6,-64,64); // Setting phase change for a couple of waves.
19-
int thatPhase = beatsin8(7,-64,64);
15+
void BlendWave::loop(CRGBPalette16 palette) {
16+
_currentPalette = palette;
17+
18+
// setting phase change for a couple of waves
19+
int thisPhase = beatsin8(6, -64, 64);
20+
int thatPhase = beatsin8(7, -64, 64);
2021

21-
for (int k=0; k<_numLEDS; k++) { // For each of the LED's in the strand, set a brightness based on a wave as follows:
22+
// for each of the LED's in the strand, set a brightness based on a wave as follows:
23+
for (int k=0; k<_numLEDS; k++) {
2224

23-
int colorIndex = cubicwave8((k*23)+thisPhase)/2 + cos8((k*15)+thatPhase)/2; // Create a wave and add a phase change and add another wave with its own phase change.. Hey, you can even change the frequencies if you wish.
24-
int thisBright = qsuba(colorIndex, beatsin8(7,0,96)); // qsub gives it a bit of 'black' dead space by setting sets a minimum value. If colorIndex < current value of beatsin8(), then bright = 0. Otherwise, bright = colorIndex..
25+
// create a wave and add a phase change and add another wave with its own phase change
26+
int colorIndex = cubicwave8((k*23)+thisPhase)/2 + cos8((k*15)+thatPhase)/2;
27+
// qsub gives it a bit of 'black' dead space by setting sets a minimum value.
28+
// If colorIndex < current value of beatsin8(), then bright = 0. Otherwise, bright = colorIndex..
29+
int thisBright = qsuba(colorIndex, beatsin8(7,0,96));
2530

26-
_neopixels[k] = ColorFromPalette(currentPalette, colorIndex, thisBright, currentBlending); // Let's now add the foreground colour.
31+
// Add the foreground colour
32+
_neopixels[k] = ColorFromPalette(_currentPalette, colorIndex, thisBright, _currentBlending);
2733
}
2834
}

fastled_patterns/BlendWave.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
#include <FastLED.h>
99

1010
// Use qsuba for smooth pixel colouring and qsubd for non-smooth pixel colouring
11-
#define qsubd(x, b) ((x>b)?b:0) // Digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
12-
#define qsuba(x, b) ((x>b)?x-b:0) // Analog Unsigned subtraction macro. if result <0, then => 0
13-
11+
// Digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
12+
#define qsubd(x, b) ((x>b)?b:0)
13+
// Analog Unsigned subtraction macro. if result <0, then => 0
14+
#define qsuba(x, b) ((x>b)?x-b:0)
1415

1516
class BlendWave {
1617
public:
1718
BlendWave(CRGB* neopixels, uint16_t numLEDS);
18-
void loop();
19+
void loop(CRGBPalette16 palette = OceanColors_p);
1920

2021
private:
2122
CRGB* _neopixels;
2223
uint16_t _numLEDS;
23-
CRGBPalette16 currentPalette; // Palette definitions
24-
CRGBPalette16 targetPalette;
25-
TBlendType currentBlending = LINEARBLEND;
24+
CRGBPalette16 _currentPalette;
25+
TBlendType _currentBlending = LINEARBLEND;
2626
};
2727

2828
#endif

0 commit comments

Comments
 (0)