#include <FastLED.h>
#define DATA_PIN 26
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 128
#define BRIGHTNESS 255
byte coordsX[NUM_LEDS] = { 0, 17, 34, 51, 68, 85, 102, 119, 0, 17, 34, 51, 68, 85, 102, 119, 0, 17, 34, 51, 68, 85, 102, 119, 0, 17, 34, 51, 68, 85, 102, 119, 0, 17, 34, 51, 68, 85, 102, 119, 0, 17, 34, 51, 68, 85, 102, 119, 0, 17, 34, 51, 68, 85, 102, 119, 0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255, 136, 153, 170, 187, 204, 221, 238, 255, 136, 153, 170, 187, 204, 221, 238, 255, 136, 153, 170, 187, 204, 221, 238, 255, 136, 153, 170, 187, 204, 221, 238, 255, 136, 153, 170, 187, 204, 221, 238, 255, 136, 153, 170, 187, 204, 221, 238, 255, 136, 153, 170, 187, 204, 221, 238, 255 };
byte coordsY[NUM_LEDS] = { 0, 0, 0, 0, 0, 0, 0, 0, 36, 36, 36, 36, 36, 36, 36, 36, 73, 73, 73, 73, 73, 73, 73, 73, 109, 109, 109, 109, 109, 109, 109, 109, 146, 146, 146, 146, 146, 146, 146, 146, 182, 182, 182, 182, 182, 182, 182, 182, 219, 219, 219, 219, 219, 219, 219, 219, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36, 36, 36, 36, 36, 36, 36, 73, 73, 73, 73, 73, 73, 73, 73, 109, 109, 109, 109, 109, 109, 109, 109, 146, 146, 146, 146, 146, 146, 146, 146, 182, 182, 182, 182, 182, 182, 182, 182, 219, 219, 219, 219, 219, 219, 219, 219, 255, 255, 255, 255, 255, 255, 255, 255 };
byte angles[NUM_LEDS] = { 19, 21, 24, 27, 32, 38, 45, 54, 15, 16, 19, 22, 26, 32, 40, 51, 10, 11, 13, 15, 19, 24, 32, 45, 5, 6, 7, 8, 10, 13, 19, 32, 0, 0, 0, 0, 0, 0, 0, 0, 250, 249, 248, 247, 245, 242, 236, 223, 245, 244, 242, 240, 236, 231, 223, 210, 240, 239, 236, 233, 229, 223, 215, 204, 64, 74, 83, 90, 96, 100, 104, 106, 64, 77, 88, 96, 101, 106, 109, 111, 64, 83, 96, 104, 109, 112, 114, 116, 64, 96, 109, 114, 118, 119, 121, 122, 0, 128, 128, 128, 128, 128, 128, 128, 191, 159, 146, 141, 137, 136, 134, 133, 191, 172, 159, 151, 146, 143, 141, 139, 191, 178, 167, 159, 154, 149, 146, 144 };
byte radii[NUM_LEDS] = { 255, 230, 206, 183, 161, 143, 127, 118, 244, 217, 191, 166, 143, 121, 103, 90, 235, 208, 180, 154, 127, 103, 81, 64, 230, 202, 173, 145, 118, 90, 64, 40, 228, 200, 171, 143, 114, 86, 57, 29, 230, 202, 173, 145, 118, 90, 64, 40, 235, 208, 180, 154, 127, 103, 81, 64, 244, 217, 191, 166, 143, 121, 103, 90, 114, 118, 127, 143, 161, 183, 206, 230, 86, 90, 103, 121, 143, 166, 191, 217, 57, 64, 81, 103, 127, 154, 180, 208, 29, 40, 64, 90, 118, 145, 173, 202, 0, 29, 57, 86, 114, 143, 171, 200, 29, 40, 64, 90, 118, 145, 173, 202, 57, 64, 81, 103, 127, 154, 180, 208, 86, 90, 103, 121, 143, 166, 191, 217 };
CRGB leds[NUM_LEDS];
#define FRAMES_PER_SECOND 120
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
uint8_t offset = 0; // rotating "base color" used by many of the patterns
uint8_t speed = 30;
boolean autoplay = true;
uint8_t autoplaySeconds = 2;
void setup()
{
// delay(3000); // 3 second delay for recovery
Serial.begin(9600);
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setCorrection(TypicalSMD5050);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000); // 1A
FastLED.setBrightness(BRIGHTNESS);
}
// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList patterns = {
// 2D map examples:
clockwisePalette,
counterClockwisePalette,
outwardPalette,
inwardPalette,
northPalette,
northEastPalette,
eastPalette,
southEastPalette,
southPalette,
southWestPalette,
westPalette,
northWestPalette,
// standard FastLED demo reel examples:
// rainbow,
// rainbowWithGlitter,
// confetti,
// sinelon,
// juggle,
// bpm
};
const uint8_t patternCount = ARRAY_SIZE(patterns);
uint8_t currentPatternIndex = 0; // Index number of which pattern is current
CRGBPalette16 IceColors_p = CRGBPalette16(CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
const CRGBPalette16 palettes[] = {
RainbowColors_p,
RainbowStripeColors_p,
CloudColors_p,
LavaColors_p,
OceanColors_p,
ForestColors_p,
PartyColors_p,
HeatColors_p,
IceColors_p,
};
const uint8_t paletteCount = ARRAY_SIZE(palettes);
uint8_t currentPaletteIndex = 0;
CRGBPalette16 currentPalette = palettes[currentPaletteIndex];
boolean autoplayPalettes = true;
uint8_t autoplayPaletteSeconds = autoplaySeconds * patternCount;
void loop()
{
// Call the current pattern function once, updating the 'leds' array
patterns[currentPatternIndex]();
offset = beat8(speed);
// do some periodic updates
EVERY_N_SECONDS(autoplaySeconds)
{
if (autoplay)
{
nextPattern(); // change patterns periodically
}
}
EVERY_N_SECONDS(autoplayPaletteSeconds)
{
// change palettes periodically
if (autoplayPalettes)
{
nextPalette();
}
}
// send the 'leds' array out to the actual LED strip
// FastLED.show(); called automatically, internally by FastLED.delay below:
// insert a delay to keep the framerate modest
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
currentPatternIndex = (currentPatternIndex + 1) % patternCount;
}
void nextPalette()
{
// add one to the current palette number, and wrap around at the end
currentPaletteIndex = (currentPaletteIndex + 1) % paletteCount;
currentPalette = palettes[currentPaletteIndex];
}
// 2D map examples:
void clockwisePalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + angles[i]);
}
}
void counterClockwisePalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - angles[i]);
}
}
void outwardPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - radii[i]);
}
}
void inwardPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + radii[i]);
}
}
void northPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - coordsY[i]);
}
}
void northEastPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - (coordsX[i] + coordsY[i]));
}
}
void eastPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - coordsX[i]);
}
}
void southEastPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset - coordsX[i] + coordsY[i]);
}
}
void southPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsY[i]);
}
}
void southWestPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsX[i] + coordsY[i]);
}
}
void westPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsX[i]);
}
}
void northWestPalette()
{
for (uint16_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = ColorFromPalette(currentPalette, offset + coordsX[i] - coordsY[i]);
}
}
// standard FastLED demo reel examples:
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow(leds, NUM_LEDS, offset, 7);
}
void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}
void addGlitter(fract8 chanceOfGlitter)
{
if (random8() < chanceOfGlitter)
{
leds[random16(NUM_LEDS)] += CRGB::White;
}
}
void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy(leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV(offset + random8(64), 200, 255);
}
void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy(leds, NUM_LEDS, 20);
int pos = beatsin16(13, 0, NUM_LEDS - 1);
leds[pos] += CHSV(offset, 255, 192);
}
void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
for (int i = 0; i < NUM_LEDS; i++)
{ // 9948
leds[i] = ColorFromPalette(palette, offset + (i * 2), beat - offset + (i * 10));
}
}
const byte dotCount = 3;
const byte hues = 240 / dotCount;
void juggle()
{
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy(leds, NUM_LEDS, 20);
for (int i = 0; i < dotCount; i++)
{
leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(i * hues, 200, 255);
}
}