#define FASTLED_ALLOW_INTERRUPTS 0
#include <FastLED.h>
FASTLED_USING_NAMESPACE
#define DATA_PIN 3
#define MAX_POWER_MILLIAMPS 800
#define LED_TYPE NEOPIXEL
#define COLOR_ORDER RGB
const uint8_t kMatrixWidth = 34;
const uint8_t kMatrixHeight = 7;
const uint8_t kMatrixNumLeds = kMatrixWidth * kMatrixHeight;
const bool kMatrixSerpentineLayout = false;
const bool kMatrixVertical = false;
const uint8_t divisions = 7;
const int minRangeSize = 5;
const int rangeMin = 1;
const int rangeMax = 50;
const int maxDivisions = 5;
uint8_t curPalleteIndex = 0;
//////////////////////////////////////////////////////////////////////////
DEFINE_GRADIENT_PALETTE( pallete_purple_red_purple ) {
0, 72, 0, 95,
128, 255, 0, 88,
255, 72, 0, 95};
CRGBPalette16 currentPalette;
TBlendType currentBlending;
CRGB leds[kMatrixNumLeds];
void setup() {
delay(3000); // 3 second delay for boot recovery, and a moment of silence
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, kMatrixNumLeds);
// currentPalette = pallete_purple_red_purple;
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
FastLED.clear();
FastLED.show();
delay(1000);
}
void loop()
{
randomly_split_range(0, kMatrixWidth, 0);
FastLED.show();
delay(2000);
}
void randomly_split_range(int min, int max, int counter)
{
if (min + minRangeSize < max - minRangeSize && counter < maxDivisions) {
int rand_divider = min + minRangeSize + (rand() % (max - minRangeSize - (min + minRangeSize)));
counter++;
randomly_split_range(min, rand_divider, counter);
randomly_split_range(rand_divider + 1, max, counter);
} else {
fillColumns(min, max);
curPalleteIndex+=20;
}
}
void fillColumns(int x1, int x2)
{
for( int i = x1; i < (x2 + 1); i++) {
fillColumn(i);
}
}
void fillColumn(int x)
{
for( uint8_t y = 0; y < kMatrixHeight; y++) {
leds[XY(x, y)] = ColorFromPalette( currentPalette, curPalleteIndex, 200, currentBlending);
}
}
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false) {
if (kMatrixVertical == false) {
i = (y * kMatrixWidth) + x;
} else {
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
}
}
if( kMatrixSerpentineLayout == true) {
if (kMatrixVertical == false) {
if( y & 0x01) {
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
} else {
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
} else { // vertical positioning
if ( x & 0x01) {
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
} else {
i = kMatrixHeight * (kMatrixWidth - x) - (y+1);
}
}
}
return i;
}