10#define COLOR_ORDER GRB
13const uint8_t kMatrixWidth = 16;
14const uint8_t kMatrixHeight = 16;
17const bool kMatrixSerpentineLayout =
true;
46#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
47#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
50CRGB leds[kMatrixWidth * kMatrixHeight];
70uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
93 uint8_t dataSmoothing = 0;
95 dataSmoothing = 200 - (speed * 4);
98 for(
int i = 0; i < MAX_DIMENSION; i++) {
99 int ioffset = scale * i;
100 for(
int j = 0; j < MAX_DIMENSION; j++) {
101 int joffset = scale * j;
103 uint8_t data =
inoise8(x + ioffset,y + joffset,z);
108 data =
qsub8(data,16);
111 if( dataSmoothing ) {
112 uint8_t olddata = noise[i][j];
113 uint8_t newdata =
scale8( olddata, dataSmoothing) +
scale8( data, 256 - dataSmoothing);
128void mapNoiseToLEDsUsingPalette()
130 static uint8_t ihue=0;
132 for(
int i = 0; i < kMatrixWidth; i++) {
133 for(
int j = 0; j < kMatrixHeight; j++) {
138 uint8_t index = noise[j][i];
139 uint8_t bri = noise[i][j];
155 leds[
XY(i,j)] = color;
164 ChangePaletteAndSettingsPeriodically();
171 mapNoiseToLEDsUsingPalette();
190#define HOLD_PALETTES_X_TIMES_AS_LONG 1
192void ChangePaletteAndSettingsPeriodically()
194 uint8_t secondHand = ((millis() / 1000) / HOLD_PALETTES_X_TIMES_AS_LONG) % 60;
195 static uint8_t lastSecond = 99;
197 if( lastSecond != secondHand) {
198 lastSecond = secondHand;
199 if( secondHand == 0) { currentPalette =
RainbowColors_p; speed = 20; scale = 30; colorLoop = 1; }
200 if( secondHand == 5) { SetupPurpleAndGreenPalette(); speed = 10; scale = 50; colorLoop = 1; }
201 if( secondHand == 10) { SetupBlackAndWhiteStripedPalette(); speed = 20; scale = 30; colorLoop = 1; }
202 if( secondHand == 15) { currentPalette =
ForestColors_p; speed = 8; scale =120; colorLoop = 0; }
203 if( secondHand == 20) { currentPalette =
CloudColors_p; speed = 4; scale = 30; colorLoop = 0; }
204 if( secondHand == 25) { currentPalette =
LavaColors_p; speed = 8; scale = 50; colorLoop = 0; }
205 if( secondHand == 30) { currentPalette =
OceanColors_p; speed = 20; scale = 90; colorLoop = 0; }
206 if( secondHand == 35) { currentPalette =
PartyColors_p; speed = 20; scale = 30; colorLoop = 1; }
207 if( secondHand == 40) { SetupRandomPalette(); speed = 20; scale = 20; colorLoop = 1; }
208 if( secondHand == 45) { SetupRandomPalette(); speed = 50; scale = 50; colorLoop = 1; }
209 if( secondHand == 50) { SetupRandomPalette(); speed = 90; scale = 90; colorLoop = 1; }
210 if( secondHand == 55) { currentPalette =
RainbowStripeColors_p; speed = 30; scale = 20; colorLoop = 1; }
219void SetupRandomPalette()
232void SetupBlackAndWhiteStripedPalette()
245void SetupPurpleAndGreenPalette()
247 CRGB purple =
CHSV( HUE_PURPLE, 255, 255);
248 CRGB green =
CHSV( HUE_GREEN, 255, 255);
252 green, green, black, black,
253 purple, purple, black, black,
254 green, green, black, black,
255 purple, purple, black, black );
262uint16_t
XY( uint8_t x, uint8_t y)
265 if( kMatrixSerpentineLayout ==
false) {
266 i = (y * kMatrixWidth) + x;
268 if( kMatrixSerpentineLayout ==
true) {
271 uint8_t reverseX = (kMatrixWidth - 1) - x;
272 i = (y * kMatrixWidth) + reverseX;
275 i = (y * kMatrixWidth) + x;
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
RGB color palette with 16 discrete values.
uint16_t XY(uint8_t, uint8_t)
Forward declaration of the function "XY" which must be provided by the application for use in two-dim...
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
LIB8STATIC uint8_t dim8_raw(uint8_t x)
Adjust a scaling value for dimming.
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
uint8_t inoise8(uint16_t x, uint16_t y, uint16_t z)
8-Bit, fixed point implementation of Perlin's noise.
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Get a color from a palette.
const TProgmemRGBPalette16 RainbowStripeColors_p
HSV Rainbow colors with alternatating stripes of black.
const TProgmemRGBPalette16 OceanColors_p
Ocean colors, blues and whites.
const TProgmemRGBPalette16 CloudColors_p
Cloudy color palette.
const TProgmemRGBPalette16 ForestColors_p
Forest colors, greens.
const TProgmemRGBPalette16 LavaColors_p
Lava color palette.
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
const TProgmemRGBPalette16 RainbowColors_p
HSV Rainbow.
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Representation of an RGB pixel (Red, Green, Blue)