#include <FastLED.h>
#define LED_COUNT 48 // the number of pixels on the strip
#define DATA_PIN 11 //
#define PIN_BUTTON 2
#define PIN_LED 13
// default values. You will change them via the Web interface
uint8_t brightness = 255;
uint32_t duration = 10000; // (10s) duration of the effect in the loop
uint32_t lastChange = 0;
uint8_t currentEffect = 0; // 0 - 43
bool isLoopEffect = true;
//bool isRandom = false;
// effects that will be in the loop
uint8_t favEffects[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43};
uint8_t numFavEffects = sizeof(favEffects);
uint8_t effect = favEffects[currentEffect];
CRGBArray<LED_COUNT> leds;
// variables for basic effects settings
uint8_t _delay = 20;
uint8_t _step = 10;
uint8_t _hue = 0;
uint8_t _sat = 255;
//Effects
uint8_t idex = 0;
uint8_t ihue = 0;
uint8_t isat = 255;
uint8_t ibright = 0;
uint16_t TOP_INDEX = uint16_t(LED_COUNT / 2); // center of the stip
uint8_t EVENODD = LED_COUNT % 2;
uint8_t bouncedirection = 0;
int ledsX[LED_COUNT][3]; // array for storing random pixel values
//button
volatile bool butt_flag = false;
volatile bool butt;
volatile unsigned long last_press = 0;
volatile bool isLE = true;
// debug
unsigned long last_print = 0;
//for blueGradientPal
uint8_t colorIndex[LED_COUNT];
uint8_t colorIndex1[LED_COUNT];
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// tell FastLED about the LED strip configuration
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, LED_COUNT);
// set the brightness
FastLED.setBrightness(brightness);
FastLED.clear();
FastLED.show(); // set new changes for led
pinMode(PIN_BUTTON,INPUT_PULLUP); // internal pull-up resistor
attachInterrupt (digitalPinToInterrupt (PIN_BUTTON), changeEffect, CHANGE); // pressed
pinMode(PIN_LED, OUTPUT);
digitalWrite(PIN_LED, !isLoopEffect);
//for blueGradientPal
//Fill the colorIndex array with random numbers
for (int i = 0; i < LED_COUNT; i++) {
colorIndex[i] = random8();
colorIndex1[i] = random8();
}
}
void loop() {
/*
butt = !digitalRead(11);
if (butt && !butt_flag && (millis() - last_press > 50) ) {
butt_flag = true;
isLoopEffect = !isLoopEffect;
digitalWrite(13, !isLoopEffect);
last_press = millis();
}
if (!butt && butt_flag)
butt_flag = false;
*/
cli();
isLoopEffect = isLE;
sei();
digitalWrite(PIN_LED, !isLoopEffect);
if (isLoopEffect)
if ((millis() - lastChange) > duration) {
setFavEffects(favEffects, numFavEffects);
Serial.println(effect);
}
/*
if (isRandom)
if ((millis() - lastChange) > duration) {
lastChange = millis();
effect = favEffects[random(1, numFavEffects+1)];
currentEffect = effect;
}
*/
/*
if (millis() - last_print > 1000) {
Serial.println(effect);
last_print = millis();
}
*/
setEffect(effect);
}
// ------------------------------- Interrupt for button
void changeEffect() {
butt = !digitalRead(PIN_BUTTON);
if (butt && !butt_flag && (millis() - last_press > 250) ) {
butt_flag = true;
last_press = millis();
isLE = !isLE;
}
if (!butt && butt_flag)
butt_flag = false;
}
// -------------------------------
void updateColor (byte r, byte g, byte b) {
for (int i = 0; i < LED_COUNT; i++) {
leds[i].setRGB(r,g,b);
}
}
void updatePixel (int i, byte r, byte g, byte b) {
leds[i].setRGB(r,g,b);
}
void setPixel (int Pixel, byte red, byte green, byte blue) {
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
}
void setAll (byte red, byte green, byte blue) {
for (int i = 0; i < LED_COUNT; i++) {
setPixel(i, red, green, blue);
}
//FastLED.show();
}
void fadeall( ) {
for (int i = 0; i < LED_COUNT; i++) {
leds[i].nscale8(250);
}
}
// 0 ------------------------------ RGBLoop
void RGBLoop() {
#define LAST_J 15
static int rgbl_fi = 0;
static int rgbl_j = 0;
static int rgbl_k = 0;
switch (rgbl_j) {
case 0: setAll(rgbl_k, 0, 0); break;
case 1: setAll(0, rgbl_k, 0); break;
case 2: setAll(0, 0, rgbl_k); break;
case 3: setAll(rgbl_k, rgbl_k, 0); break;
case 4: setAll(rgbl_k, 0, rgbl_k); break;
case 5: setAll(0, rgbl_k, rgbl_k); break;
case 6: setAll(rgbl_k, rgbl_k, rgbl_k); break;
case 7: setAll(rgbl_k, byte(float(rgbl_k)/255.0 * 20.0), byte(float(rgbl_k)/255.0 * 147.0)); break; //DeepPink
case 8: setAll(rgbl_k, byte(float(rgbl_k)/255.0 * 69.0), 0); break; //OrangeRed
case 9: setAll(rgbl_k, byte(float(rgbl_k)/255.0 * 215.0), 0); break; //Gold
case 10: setAll(byte(float(rgbl_k)/255.0 * 210.0), byte(float(rgbl_k)/255.0 * 105.0), byte(float(rgbl_k)/255.0 * 30.0)); break; //Chocolate
case 11: setAll(byte(float(rgbl_k)/255.0 * 128.0), 0, byte(float(rgbl_k)/255.0 * 128.0)); break; //Purple
case 12: setAll(byte(float(rgbl_k)/255.0 * 173.0), rgbl_k, byte(float(rgbl_k)/255.0 * 47.0)); break; //GreenYellow
case 13: setAll(byte(float(rgbl_k)/255.0 * 127.0), rgbl_k, byte(float(rgbl_k)/255.0 * 212.0)); break;//Aquamarine
case 14: setAll(rgbl_k, byte(float(rgbl_k)/255.0 * 228.0), byte(float(rgbl_k)/255.0 * 225.0)); break;//MistyRose
case 15: setAll(byte(float(rgbl_k)/255.0 * 199.0), byte(float(rgbl_k)/255.0 * 228.0), byte(float(rgbl_k)/255.0 * 225.0)); break;//MediumVioletRed
}
FastLED.show();
delay(25);
if (rgbl_fi == 0) // Fade IN
{
rgbl_k++;
if (rgbl_k > 255)
{
rgbl_k = 255;
rgbl_fi = 1;
}
}
if (rgbl_fi == 1) // Fade OUT
{
rgbl_k--;
if (rgbl_k < 0)
{
rgbl_k = 0;
rgbl_fi = 0;
rgbl_j++; if (rgbl_j > LAST_J) rgbl_j = 0;
}
}
}
// -------------------------------- RAINBOW LOOP FADE -------------------------------------
// smooth color change
void rainbowFade() {
ihue++;
if (ihue > 255){
ihue = 0;
}
for (int idex = 0 ; idex < LED_COUNT; idex++) {
leds[idex] = CHSV(ihue, isat, 255);
}
LEDS.show();
delay(_delay);
}
// -------------------------------- RAINBOW LOOP -------------------------------------
// rotating rainbow
void rainbowLoop() {
idex++;
ihue = ihue + _step;
if (idex >= LED_COUNT) {
idex = 0;
}
if (ihue > 255){
ihue = 0;
}
leds[idex] = CHSV(ihue, isat, 255);
LEDS.show();
delay(_delay);
}
// ------------------------------- SNOW SPARKLE ---------------------------------------
void snowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
static unsigned long last_pixel = 0;
setAll(red, green, blue);
int Pixel = random(LED_COUNT);
if (millis() - last_pixel <= SparkleDelay) {
setPixel(Pixel, 0xff, 0xff, 0xff);
}
else {
setPixel(Pixel, red, green, blue);
if (millis() - last_pixel > (SparkleDelay + SpeedDelay))
last_pixel = millis();
}
FastLED.show();
}
//------------------------------- RADIATION ---------------------------------------
float rcount = 0.0;
void radiation() {
updateColor(0,0,0);
int N3 = int(LED_COUNT / 3);
int N6 = int(LED_COUNT / 6);
int N12 = int(LED_COUNT / 12);
for (int i = 0; i < N6; i++) {
rcount = rcount + .02;
if (rcount > 3.14) {
rcount = 0.0;
}
ibright = int(sin(rcount) * 255);
int j0 = (i + LED_COUNT - N12) % LED_COUNT;
int j1 = (j0 + N3) % LED_COUNT;
int j2 = (j1 + N3) % LED_COUNT;
leds[j0] = CHSV(_hue, _sat, ibright);
leds[j1] = CHSV(_hue, _sat, ibright);
leds[j2] = CHSV(_hue, _sat, ibright);
}
LEDS.show();
delay(_delay);
}
// -------------------------------- blueGradientPal -------------------------------------
DEFINE_GRADIENT_PALETTE( greenblue_gp ) {
0, 0, 255, 245,
46, 0, 21, 255,
179, 12, 250, 0,
255, 0, 255, 245
};
void blueGradientPal() {
static CRGBPalette16 greenblue = greenblue_gp;
// Color each pixel from the palette using the index from colorIndex[]
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = ColorFromPalette(greenblue, colorIndex[i]);
}
EVERY_N_MILLISECONDS(5){
for (int i = 0; i < LED_COUNT; i++) {
colorIndex[i]++;
}
}
FastLED.show();
delay(_delay);
}
// 19 -------------------------------- brightnessWave -------------------------------------
void brightnessWave() {
static CRGBPalette16 greenblue = greenblue_gp;
uint8_t sinBeat = beatsin8(30, 50, 255, 0, 0);
// Color each pixel from the palette using the index from colorIndex[]
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = ColorFromPalette(greenblue, colorIndex1[i], sinBeat);
}
EVERY_N_MILLISECONDS(5){
for (int i = 0; i < LED_COUNT; i++) {
colorIndex1[i]++;
}
}
FastLED.show();
delay(_delay);
}
// -------------------------------- RANDOM BURST -------------------------------------
// random color change
void randomBurst() {
idex = random(0, LED_COUNT);
ihue = random(0, 255);
leds[idex] = CHSV(ihue, isat, 255);
LEDS.show();
delay(_delay);
}
// -------------------------------- ColorPalette16 -------------------------------------
void colorPalette16() {
static uint8_t paletteIndex = 0;
CRGBPalette16 purplePalette = CRGBPalette16 (
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::Magenta,
CRGB::Magenta,
CRGB::Linen,
CRGB::Linen,
CRGB::Magenta,
CRGB::Magenta,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::DarkViolet,
CRGB::Linen,
CRGB::Linen
);
fill_palette(leds, LED_COUNT, paletteIndex, 255 / LED_COUNT, purplePalette, 255, LINEARBLEND);
EVERY_N_MILLISECONDS(10){
paletteIndex++;
}
LEDS.show();
delay(_delay);
}
// 14 -------------------------------- AddingWaves -------------------------------------
// running train of pixels
void addingWaves() {
uint8_t posBeat = beatsin8(30, 0, LED_COUNT - 1, 0, 0);
uint8_t posBeat2 = beatsin8(60, 0, LED_COUNT - 1, 0, 0);
uint8_t posBeat3 = beatsin16(30, 0, LED_COUNT - 1, 0, 127);
uint8_t posBeat4 = beatsin16(60, 0, LED_COUNT - 1, 0, 127);
// Wave for LED color
uint8_t colBeat = beatsin8(45, 0, 255, 0, 0);
leds[(posBeat + posBeat2) / 2] = CHSV(colBeat, 255, 255);
leds[(posBeat3 + posBeat4) / 2] = CHSV(colBeat, 255, 255);
fadeToBlackBy(leds, LED_COUNT, 10);
FastLED.show();
delay(_delay);
}
// 15 -------------------------------- blurPhaseBeat -------------------------------------
void blurPhaseBeat() {
uint8_t sinBeat = beatsin8(30, 0, LED_COUNT - 1, 0, 0);
uint8_t sinBeat2 = beatsin8(30, 0, LED_COUNT - 1, 0, 85);
uint8_t sinBeat3 = beatsin8(30, 0, LED_COUNT - 1, 0, 170);
leds[sinBeat] = CRGB::Green;
leds[sinBeat2] = CRGB::Blue;
leds[sinBeat3] = CRGB::Red;
EVERY_N_MILLISECONDS(1){
for(int i = 0; i < 4; i++) {
blur1d(leds, LED_COUNT, 50);
}
}
FastLED.show();
delay(_delay);
}
int antipodal_index(int i) {
int iN = i + TOP_INDEX;
if (i >= TOP_INDEX) {
iN =( i + TOP_INDEX ) % LED_COUNT;
}
return iN;
}
// -------------------------------- ROTATING RED/BLUE -------------------------------------
// red/blue rotation
void rotatingRedBlue() {
idex++;
if (idex >= LED_COUNT) {
idex = 0;
}
int idexR = idex;
int idexB = antipodal_index(idexR);
int thathue =(_hue + 160) % 255;
leds[idexR] = CHSV(_hue, isat, 255);
leds[idexB] = CHSV(thathue, isat, 255);
LEDS.show();
delay(_delay);
}
// 10 -------------------------------- FLICKER -------------------------------------
// random strobe light
void flicker() {
int random_bright = random(0, 255);
int random_delay = random(10, 100);
int random_bool = random(0, random_bright);
if (random_bool < 10) {
for (int i = 0 ; i < LED_COUNT; i++) {
leds[i] = CHSV(160, 50, random_bright);
}
LEDS.show();
delay(random_delay);
}
}
// 29 -------------------------------- gradientBeat -------------------------------------
DEFINE_GRADIENT_PALETTE( browngreen_gp ) {
0, 6, 255, 0, //green
71, 0, 255, 153, //bluegreen
122, 200, 200, 200, //gray
181, 110, 61, 6, //brown
255, 6, 255, 0 //green
};
void gradientBeat() {
static CRGBPalette16 orangePink = browngreen_gp;
uint16_t beatA = beatsin16(30, 0, 255);
uint16_t beatB = beatsin16(20, 0, 255);
fill_palette(leds, LED_COUNT, (beatA + beatB) / 2, 10, orangePink, 255, LINEARBLEND);
FastLED.show();
delay(_delay);
}
//---------------------------------------------
int horizontal_index(int i) {
if(i == 0) {
return 0;
}
if (i == TOP_INDEX && EVENODD == 1) {
return TOP_INDEX + 1;
}
if (i == TOP_INDEX && EVENODD == 0) {
return TOP_INDEX;
}
return LED_COUNT - i;
}
void random_red() {
int temprand;
for (int i = 0; i < LED_COUNT; i++) {
temprand = random(0, 100);
if (temprand > 50) {
leds[i].r = 255;
}
if (temprand <= 50) {
leds[i].r = 0;
}
leds[i].b = 0; leds[i].g = 0;
}
LEDS.show();
}
// -------------------------------- RULE30 -------------------------------------
// the madness of red LEDs
void rule30() {
if (bouncedirection == 0) {
random_red();
bouncedirection = 1;
}
copy_led_array();
int iCW;
int iCCW;
int y = 100;
for (int i = 0; i < LED_COUNT; i++) {
iCW = adjacent_cw(i);
iCCW = adjacent_ccw(i);
if (ledsX[iCCW][0] > y && ledsX[i][0] > y && ledsX[iCW][0] > y) {
leds[i].r = 0;
}
if (ledsX[iCCW][0] > y && ledsX[i][0] > y && ledsX[iCW][0] <= y) {
leds[i].r = 0;
}
if (ledsX[iCCW][0] > y && ledsX[i][0] <= y && ledsX[iCW][0] > y) {
leds[i].r = 0;
}
if (ledsX[iCCW][0] > y && ledsX[i][0] <= y && ledsX[iCW][0] <= y) {
leds[i].r = 255;
}
if (ledsX[iCCW][0] <= y && ledsX[i][0] > y && ledsX[iCW][0] > y) {
leds[i].r = 255;
}
if (ledsX[iCCW][0] <= y && ledsX[i][0] > y && ledsX[iCW][0] <= y) {
leds[i].r = 255;
}
if (ledsX[iCCW][0] <= y && ledsX[i][0] <= y && ledsX[iCW][0] > y) {
leds[i].r = 255;
}
if (ledsX[iCCW][0] <= y && ledsX[i][0] <= y && ledsX[iCW][0] <= y) {
leds[i].r = 0;
}
}
LEDS.show();
delay(_delay);
}
int adjacent_cw(int i) {
int r;
if (i < LED_COUNT - 1) {
r = i + 1;
} else {
r = 0;
}
return r;
}
int adjacent_ccw(int i) {
int r;
if (i > 0) {
r = i - 1;
}
else{
r = LED_COUNT - 1;
}
return r;
}
// -------------------------------- RANDOM MARCH -------------------------------------
// the madness of random LEDs
void randomMarch() {
copy_led_array();
int iCCW;
leds[0] = CHSV(random(0, 255), 255, 255);
for (int idex = 1; idex < LED_COUNT ; idex++) {
iCCW = adjacent_ccw(idex);
leds[idex].r = ledsX[iCCW][0];
leds[idex].g = ledsX[iCCW][1];
leds[idex].b = ledsX[iCCW][2];
}
LEDS.show();
delay(_delay);
}
void copy_led_array() {
for(int i = 0; i < LED_COUNT; i++ ) {
ledsX[i][0] = leds[i].r;
ledsX[i][1] = leds[i].g;
ledsX[i][2] = leds[i].b;
}
}
// -------------------------------- RWB MARCH -------------------------------------
// white blue red run in a circle
void rwbMarch() {
copy_led_array();
int iCCW;
idex++;
if (idex > 2) {
idex = 0;
}
switch(idex) {
case 0:
leds[0].r = 255;
leds[0].g = 0;
leds[0].b = 0;
break;
case 1:
leds[0].r = 255;
leds[0].g = 255;
leds[0].b = 255;
break;
case 2:
leds[0].r = 0;
leds[0].g = 0;
leds[0].b = 255;
break;
}
for (int i = 1; i < LED_COUNT; i++) {
iCCW = adjacent_ccw(i);
leds[i].r = ledsX[iCCW][0];
leds[i].g = ledsX[iCCW][1];
leds[i].b = ledsX[iCCW][2];
}
LEDS.show();
delay(_delay);
}
// -------------------------------- FLAME -------------------------------------
// flame effect
void flame() {
int idelay = random(0, 35);
float hmin = 0.1; float hmax = 45.0;
float hdif = hmax - hmin;
int randtemp = random(0, 3);
float hinc =(hdif / float(TOP_INDEX)) + randtemp;
int ihue = hmin;
for (int i = 0; i <= TOP_INDEX; i++) {
ihue = ihue + hinc;
leds[i] = CHSV(ihue, isat, 255);
int ih = horizontal_index(i);
leds[ih] = CHSV(ihue, isat, 255);
leds[TOP_INDEX].r = 255; leds[TOP_INDEX].g = 255; leds[TOP_INDEX].b = 255;
LEDS.show();
delay(idelay);
}
}
// -------------------------------- RANDOM COLOR POP -------------------------------------
// the madness of random flashes
void randomColorPop(){
idex = random(0, LED_COUNT);
ihue = random(0, 255);
updateColor(0, 0, 0);
leds[idex] = CHSV(ihue, isat, 255);
LEDS.show();
delay(_delay);
}
// -------------------------------- RAINBOW VERTICAL -------------------------------------
void rainbowVertical() {
idex++;
if (idex > TOP_INDEX) {
idex = 0;
}
ihue = ihue + _step;
if (ihue > 255) {
ihue = 0;
}
int idexA = idex;
int idexB = horizontal_index(idexA);
leds[idexA] = CHSV(ihue, isat, 255);
leds[idexB] = CHSV(ihue, isat, 255);
LEDS.show();
delay(_delay);
}
// -------------------------------- POLICE BLINKER -------------------------------------
void policeBlinker() {
int _hue = 0;
int thathue =(_hue + 160) % 255;
for (int x = 0 ; x < 5; x++) {
for (int i = 0 ; i < TOP_INDEX; i++) {
leds[i] = CHSV(_hue, isat, 255);
}
LEDS.show(); delay(_delay);
updateColor(0, 0, 0);
LEDS.show(); delay(_delay);
}
for (int x = 0 ; x < 5; x++) {
for (int i = TOP_INDEX ; i < LED_COUNT; i++) {
leds[i] = CHSV(thathue, isat, 255);
}
LEDS.show(); delay(_delay);
updateColor(0, 0, 0);
LEDS.show(); delay(_delay);
}
}
// -------------------------------- RGB PROPELLER -------------------------------------
void rgbPropeller() {
idex++;
int ghue =(_hue + 80) % 255;
int bhue =(_hue + 160) % 255;
int N3 = int(LED_COUNT / 3);
int N6 = int(LED_COUNT / 6);
int N12 = int(LED_COUNT / 12);
for (int i = 0; i < N3; i++) {
int j0 =(idex + i + LED_COUNT - N12) % LED_COUNT;
int j1 =(j0 + N3) % LED_COUNT;
int j2 =(j1 + N3) % LED_COUNT;
leds[j0] = CHSV(_hue, isat, 255);
leds[j1] = CHSV(ghue, isat, 255);
leds[j2] = CHSV(bhue, isat, 255);
}
LEDS.show();
delay(_delay);
}
// -------------------------------- KITT -------------------------------------
// random flashes of red
void kitt() {
int rand = random(0, TOP_INDEX);
for (int i = 0; i < rand; i++) {
leds[TOP_INDEX + i] = CHSV(_hue, isat, 255);
leds[TOP_INDEX - i] = CHSV(_hue, isat, 255);
LEDS.show();
delay(_delay / rand);
}
for (int i = rand; i > 0; i--) {
leds[TOP_INDEX + i] = CHSV(_hue, isat, 0);
leds[TOP_INDEX - i] = CHSV(_hue, isat, 0);
LEDS.show();
delay(_delay / rand);
}
}
// -------------------------------- MATRIX -------------------------------------
// the greens run around randomly
void matrix() {
int rand = random(0, 100);
if (rand > 90) {
leds[0] = CHSV(_hue, isat, 255);
}
else {
leds[0] = CHSV(_hue, isat, 0);
}
copy_led_array();
for (int i = 1; i < LED_COUNT; i++) {
leds[i].r = ledsX[i - 1][0];
leds[i].g = ledsX[i - 1][1];
leds[i].b = ledsX[i - 1][2];
}
LEDS.show();
delay(_delay);
}
// -------------------------------- RAINBOW LOOP FADE -------------------------------------
// smooth rotating rainbow
void rainbowLoopFade() {
ihue -= 1;
fill_rainbow(leds, LED_COUNT, ihue);
LEDS.show();
delay(_delay);
}
// -------------------------------- FIRE -------------------------------------
void fire(int Cooling, int Sparking, int SpeedDelay) {
static byte heat[LED_COUNT];
int cooldown;
for (int i = 0; i < LED_COUNT; i++) {
cooldown = random(0,((Cooling * 10) / LED_COUNT) + 2);
if (cooldown > heat[i]){
heat[i] = 0;
} else{
heat[i] = heat[i] - cooldown;
}
}
for (int k = LED_COUNT - 1; k >= 2; k--) {
heat[k] =(heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
}
if ( random(255) < Sparking ) {
int y = random(7);
heat[y] = heat[y] + random(160, 255);
}
for ( int j = 0; j < LED_COUNT; j++) {
setPixelHeatColor(j, heat[j] );
}
FastLED.show();
delay(SpeedDelay);
}
void setPixelHeatColor(int Pixel, byte temperature) {
byte t192 = round((temperature / 255.0) * 191);
byte heatramp = t192 & 0x3F;
heatramp <<= 2;
if ( t192 > 0x80) {
setPixel(Pixel, 255, 255, heatramp);
} else if ( t192 > 0x40 ) {
setPixel(Pixel, 255, heatramp, 0);
} else {
setPixel(Pixel, heatramp, 0, 0);
}
}
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for (int i =((LED_COUNT - EyeSize) / 2); i >= 0; i--) {
setAll(0, 0, 0);
setPixel(i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(i + j, red, green, blue);
}
setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
setPixel(LED_COUNT - i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(LED_COUNT - i - j, red, green, blue);
}
setPixel(LED_COUNT - i - EyeSize - 1, red / 10, green / 10, blue / 10);
FastLED.show();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for (int i = 0; i <=((LED_COUNT - EyeSize) / 2); i++) {
setAll(0, 0, 0);
setPixel(i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(i + j, red, green, blue);
}
setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
setPixel(LED_COUNT - i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(LED_COUNT - i - j, red, green, blue);
}
setPixel(LED_COUNT - i - EyeSize - 1, red / 10, green / 10, blue / 10);
FastLED.show();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for (int i = 0; i < LED_COUNT - EyeSize - 2; i++) {
setAll(0, 0, 0);
setPixel(i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(i + j, red, green, blue);
}
setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
FastLED.show();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
// -------------------------------- SPARKLE -------------------------------------
// random flashes of white
void sparkle(byte red, byte green, byte blue, int SpeedDelay) {
int Pixel = random(LED_COUNT);
static unsigned long last_pixel = 0;
setPixel(Pixel, red, green, blue);
LEDS.show();
if (millis() - last_pixel > SpeedDelay) {
//delay(SpeedDelay);
setPixel(Pixel, 0, 0, 0);
last_pixel = millis();
}
}
// -------------------------------- THEATER CHASE -------------------------------------
// running every 3 pixels
void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
for (int j = 0; j < 10; j++) {
for (int q = 0; q < 3; q++) {
for(int i = 0; i < LED_COUNT; i = i + 3) {
setPixel(i + q, red, green, blue);
}
FastLED.show();
delay(SpeedDelay);
for (int i = 0; i < LED_COUNT; i = i + 3) {
setPixel(i + q, 0, 0, 0);
}
}
}
}
// -------------------------------- STROBE -------------------------------------
// stroboscopic effect
void strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause) {
for (int j = 0; j < StrobeCount; j++) {
setAll(red, green, blue);
FastLED.show();
delay(FlashDelay);
setAll(0, 0, 0);
FastLED.show();
delay(FlashDelay);
}
delay(EndPause);
}
// -------------------------------- BLUE FIRE -------------------------------------
// blue line fire
void blueFire(int Cooling, int Sparking, int SpeedDelay) {
static byte heat[LED_COUNT];
int cooldown;
for (int i = 0; i < LED_COUNT; i++) {
cooldown = random(0,((Cooling * 10) / LED_COUNT) + 2);
if (cooldown > heat[i]) {
heat[i] = 0;
} else {
heat[i] = heat[i] - cooldown;
}
}
for (int k = LED_COUNT - 1; k >= 2; k--) {
heat[k] =(heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
}
if(random(255) < Sparking ) {
int y = random(7);
heat[y] = heat[y] + random(160, 255);
}
for(int j = 0; j < LED_COUNT; j++) {
setPixelHeatColorBlue(j, heat[j] );
}
FastLED.show();
delay(SpeedDelay);
}
void setPixelHeatColorBlue(int Pixel, byte temperature) {
byte t192 = round((temperature / 255.0) * 191);
byte heatramp = t192 & 0x03;
heatramp <<= 2;
if ( t192 > 0x03) {
setPixel(Pixel, heatramp,255, 255);
} else if( t192 > 0x40 ) {
setPixel(Pixel, 255, heatramp, 0);
} else {
setPixel(Pixel, 0, 0, heatramp);
}
}
// -------------------------------- FADE TO CENTER -------------------------------------
// blurring colors
void fadeToCenter() {
static uint8_t hue;
for (int i = 0; i < LED_COUNT/2; i++) {
leds.fadeToBlackBy(40);
leds[i] = CHSV(hue++,255,255);
leds(LED_COUNT/2,LED_COUNT-1) = leds(LED_COUNT/2 - 1 ,0);
FastLED.delay(33);
}
}
// -------------------------------- RUNNER CHAMELEON -------------------------------------
// a steam train running in a circle
void runnerChameleon() {
static uint8_t hue = 0;
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
leds[i] = CRGB::Black;
// fadeall();
delay(10);
}
}
// -------------------------------- BLENDE -------------------------------------
void blende() {
static uint8_t hue = 0;
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
// leds[i] = CRGB::Black;
fadeall();
delay(10);
}
for (int i = (LED_COUNT)-1; i >= 0; i--) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
// leds[i] = CRGB::Black;
fadeall();
delay(10);
}
}
// -------------------------------- BLENDE 2 -------------------------------------
void blende_2() {
static uint8_t hue = 0;
for (int i = 0; i < LED_COUNT; i++) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
leds[i] = CRGB::Black;
fadeall();
delay(10);
}
for (int i = (LED_COUNT)-1; i >= 0; i--) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
// leds[i] = CRGB::Black;
fadeall();
delay(10);
}
}
// 34 -------------------------------------------- movingDot
void movingDot(){
uint16_t sinBeat = beatsin16(30, 0, LED_COUNT - 1, 0, 0);
leds[sinBeat] = CRGB::Blue;
fadeToBlackBy(leds, LED_COUNT, 10);
FastLED.show();
delay(20);
}
// 35 -------------------------------------------- movingPixel
CRGB background[LED_COUNT];
void drawBackground() {
// A simple plasma effect
fill_noise16 (background, LED_COUNT, 1, millis(), 30, 1, 0, 50, millis() / 3, 10);
}
void drawMovingPixel() {
// A pixel that moves back and forth using noise
uint16_t pos = inoise16(millis() * 100);
pos = constrain(pos, 13000, 51000);
pos = map(pos, 13000, 51000, 0, LED_COUNT - 1);
leds[pos] = CRGB::Red;
}
void movingPixel(){
drawBackground();
drawMovingPixel();
EVERY_N_MILLISECONDS(20) {
fadeToBlackBy(leds, LED_COUNT, 10);
nblend(leds, background, LED_COUNT, 30);
}
FastLED.show();
delay(20);
}
// 36 ---------------------------------------- paletteKnife
DEFINE_GRADIENT_PALETTE( Sunset_Real_gp ) {
0, 120, 0, 0,
22, 179, 22, 0,
51, 255,104, 0,
85, 167, 22, 18,
135, 100, 0,103,
198, 16, 0,130,
255, 0, 0,160};
uint8_t paletteIndex = 0;
void paletteKnife(){
static CRGBPalette16 myPal = Sunset_Real_gp;
fill_palette(leds, LED_COUNT, paletteIndex, 255 / LED_COUNT, myPal, 255, LINEARBLEND);
EVERY_N_MILLISECONDS(10){
paletteIndex++;
}
FastLED.show();
delay(20);
}
// 37 ----------------------------------- phaseBeat
void phaseBeat(){
uint8_t sinBeat = beatsin8(30, 0, LED_COUNT - 1, 0, 0);
uint8_t sinBeat2 = beatsin8(30, 0, LED_COUNT - 1, 0, 85);
uint8_t sinBeat3 = beatsin8(30, 0, LED_COUNT - 1, 0, 170);
leds[sinBeat] = CRGB::Blue;
leds[sinBeat2] = CRGB::Red;
leds[sinBeat3] = CRGB::White;
fadeToBlackBy(leds, LED_COUNT, 10);
FastLED.show();
delay(20);
}
// 38 -------------------------- rainbowBeat
void rainbowBeat(){
uint16_t beatA = beatsin16(30, 0, 255);
uint16_t beatB = beatsin16(20, 0, 255);
fill_rainbow(leds, LED_COUNT, (beatA+beatB)/2, 8);
FastLED.show();
delay(20);
}
// 39 ----------------------------confetti
void confetti(){
static byte baza = 0;
int pos = random16(LED_COUNT);
fadeToBlackBy(leds, LED_COUNT, 2);
leds[pos] += CHSV(baza++ + random8(64), 200, 255);
FastLED.setBrightness(brightness);
FastLED.show();
delay(20);
}
// 40 ------------------------------------ focusPocus
void focusPocus(){
static byte baza = 0;
fadeToBlackBy(leds, LED_COUNT, 2);
for (int i = 0; i < 8; i++) {
leds[beatsin16(i + 7, 0, LED_COUNT - 1)] |= CHSV(baza+=16, 200, 255);
}
FastLED.setBrightness(brightness);
FastLED.show();
delay(20);
}
// 41 ------------------------------------------- Strobe 1
void strobe1(int StrobeCount, int FlashDelay, int EndPause) {
static unsigned long last_strobe = 0;
static int sc = 0;
static int kg = 255;
static int kb = 255;
static int kr = 255;
if (millis() - last_strobe < FlashDelay){
setAll(kr, kg, kb);
FastLED.show();
} else if (millis() - last_strobe < (FlashDelay * 2)) {
setAll(0, 0, 0);
FastLED.show();
} else {
if (sc < StrobeCount) {
sc++;
last_strobe = millis();
}
else {
if (millis() - last_strobe > (FlashDelay * 2 + EndPause)) {
kg = random(255);
kb = random(255);
kr = random(255);
sc = 0;
}
}
}
}
// 42 ----------------------------------- theaterChaseRainbow
// used by rainbowCycle and theaterChaseRainbow
byte * Wheel(byte WheelPos) {
static byte c[3];
if (WheelPos < 85) {
c[0] = WheelPos * 3;
c[1] = 255 - WheelPos * 3;
c[2] = 0;
} else if (WheelPos < 170) {
WheelPos -= 85;
c[0] = 255 - WheelPos * 3;
c[1] = 0;
c[2] = WheelPos * 3;
} else {
WheelPos -= 170;
c[0] = 0;
c[1] = WheelPos * 3;
c[2] = 255 - WheelPos * 3;
}
return c;
}
//--------
void theaterChaseRainbow(int SpeedDelay) {
static unsigned long last_tcr = 0;
byte *c;
static int j = 0;
static int q = 0;
static bool first = false;
// for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
// for (int q = 0; q < 3; q++) {
if (millis() - last_tcr <= SpeedDelay) {
if (!first) {
for (int i = 0; i < LED_COUNT; i = i + 3) {
c = Wheel( (i + j) % 255);
setPixel(i + q, *c, *(c + 1), *(c + 2)); //turn every third pixel on
}
FastLED.show();
first = true;
}
}
else {
for (int i = 0; i < LED_COUNT; i = i + 3) {
setPixel(i + q, 0, 0, 0); //turn every third pixel off
}
FastLED.show();
if (q < 2) q++;
else {
q = 0;
if (j < 255) j++;
else j = 0;
}
first = false;
last_tcr = millis();
}
}
// 43 ------------------------------------- meteorRain
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
static unsigned long last_mr = 0;
static int i = 0;
static bool first = false;
static bool init = false;
if (!init) {setAll(0, 0, 0); init = true;}
if (millis() - last_mr <= SpeedDelay) {
// fade brightness all LEDs one step
if (!first) {
//setAll(0, 0, 0);
for (int j = 0; j < LED_COUNT; j++) {
if ( (!meteorRandomDecay) || (random(10) > 5) ) {
leds[j].fadeToBlackBy(meteorTrailDecay);
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ( ( i - j < LED_COUNT) && (i - j >= 0) ) {
setPixel(i - j, red, green, blue);
}
}
FastLED.show();
first = true;
}
} else {
if (i < LED_COUNT + LED_COUNT) i++; else i = 0;
first = false;
last_mr = millis();
}
}
//------------------------------------------
void setFavEffects(const uint8_t *arr, uint8_t count) {
currentEffect++;
if (currentEffect > (count-1))
currentEffect = 0;
effect = arr[currentEffect];
lastChange = millis();
}
//--------------------------------- call the desired effect
void setEffect(const uint8_t num) {
switch(num) {
case 0: RGBLoop(); break;
case 1: rainbowFade(); _delay = 20; break;
case 2: rainbowLoop(); _delay = 20; break;
case 3: rainbowLoopFade(); _delay = 5; break;
case 4: rainbowVertical(); _delay = 50; _step = 15; break;
case 5: randomMarch(); _delay = 40; break;
case 6: rgbPropeller(); _delay = 25; break;
case 7: fire(55, 120, _delay); _delay = 15; break;
case 8: blueFire(55, 250, _delay); _delay = 15; break;
case 9: randomBurst(); _delay = 20; break;
case 10: flicker(); _delay = 20; break;
case 11: randomColorPop(); _delay = 35; break;
case 12: snowSparkle(0x10, 0x10, 0x10, 20, random(100, 1000)); break;
case 13: colorPalette16(); _delay = 20; _hue = 0; break;
case 14: addingWaves(); _delay = 20; _hue = 0; break;
case 15: blurPhaseBeat(); _delay = 20; _hue = 0; break;
case 16: rotatingRedBlue(); _delay = 40; _hue = 0; break;
case 17: matrix(); _delay = 50; _hue = 95; break;
case 18: radiation(); _delay = 60; _hue = 95; break;
case 19: brightnessWave(); _delay = 20; break;
case 20: blueGradientPal(); _delay = 20; _hue = 0; break;
case 21: sparkle(0xff, 0xff, 0xff, 0); break;
// heavy effects (have nested loops and long delays)
// don't be surprised when your ESP will slow down with a quick change of brightness for them
case 22: rwbMarch(); _delay = 80; break;
case 23: flame(); break;
case 24: theaterChase(255, 0, 0, _delay); _delay = 50; break;
case 25: strobe(255, 255, 255, 10, _delay, 1000); _delay = 100; break;
case 26: policeBlinker(); _delay = 25; break;
case 27: kitt(); _delay = 100; break;
case 28: rule30(); _delay = 100; break;
case 29: gradientBeat(); _delay = 20; break;
case 30: fadeToCenter(); break;
case 31: runnerChameleon(); break;
case 32: blende(); break;
case 33: blende_2();break;
case 34: movingDot();break;
case 35: movingPixel();break;
case 36: paletteKnife();break;
case 37: phaseBeat(); break;
case 38: rainbowBeat(); break;
case 39: confetti(); break;
case 40: focusPocus(); break;
case 41: strobe1(20, 50, 1000);break;
case 42: theaterChaseRainbow(50);break;
case 43: meteorRain(0xff, 0xff, 0xff, 10, 64, true, 20);break;
}
}