Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <ESP8266WiFi.h>
- #include <PubSubClient.h>
- #define FASTLED_INTERRUPT_RETRY_COUNT 0
- #include <FastLED.h>
- #include <ArduinoOTA.h>
- #include <ESP8266mDNS.h>
- #include <WiFiUdp.h>
- /************ WIFI and MQTT INFORMATION (CHANGE THESE FOR YOUR SETUP) ******************/
- #define wifi_ssid "**" //enter your WIFI SSID
- #define wifi_password "**" //enter your WIFI Password
- /**************************** FOR OTA **************************************************/
- #define SENSORNAME "Holiday LED Arduino" //change this to whatever you want to call your device
- #define OTApassword "**" //the password you will need to enter to upload remotely via the ArduinoIDE
- int OTAport = 8266;
- #define mqtt_server "192.168.145.245" // Enter your MQTT server adderss or IP. I use my DuckDNS adddress (yourname.duckdns.org) in this field
- #define mqtt_user "**" //enter your MQTT username
- #define mqtt_password "**" //enter your password
- /************ FastLED Defintions ******************/
- #define DATA_PIN D4 //on the NodeMCU 1.0, FastLED will default to the D5 pin after throwing an error during compiling. Leave as is.
- #define LED_TYPE WS2812B //change to match your LED type
- #define COLOR_ORDER GRB //change to match your LED configuration, ws2812 are GRB, 2811 are RGB
- #define NUM_LEDS 223 //change to match your setup, for multiple runs of LEDs use the number of the run with the most LEDs.
- ///////////////DrZzs Palettes for custom BPM effects//////////////////////////
- ///////////////Add any custom palettes here//////////////////////////////////
- //Thanksgiving colors
- // Gradient palette "bhw2_thanks_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_thanks.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 36 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bhw2_thanks_gp ) {
- 0, 9, 5, 1,
- 48, 25, 9, 1,
- 76, 137, 27, 1,
- 96, 98, 42, 1,
- 124, 144, 79, 1,
- 153, 98, 42, 1,
- 178, 137, 27, 1,
- 211, 23, 9, 1,
- 255, 9, 5, 1};
- //Red/Pink colors
- // Gradient palette "bhw2_redrosey_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_redrosey.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 32 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bhw2_redrosey_gp ) {
- 0, 103, 1, 10,
- 33, 109, 1, 12,
- 76, 159, 5, 48,
- 119, 175, 55,103,
- 127, 175, 55,103,
- 178, 159, 5, 48,
- 221, 109, 1, 12,
- 255, 103, 1, 10};
- //Blue to Red - has light blue white and pink
- // Gradient palette "bluered_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/h5/tn/bluered.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 12 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bluered_gp ) {
- 0, 0, 0,255,
- 127, 255,255,255,
- 255, 255, 0, 0};
- //Green and Red
- // Gradient palette "bhw2_xmas_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xmas.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 48 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bhw2_xmas_gp ) {
- 0, 0, 12, 0,
- 40, 0, 55, 0,
- 66, 1,117, 2,
- 77, 1, 84, 1,
- 81, 0, 55, 0,
- 119, 0, 12, 0,
- 153, 42, 0, 0,
- 181, 121, 0, 0,
- 204, 255, 12, 8,
- 224, 121, 0, 0,
- 244, 42, 0, 0,
- 255, 42, 0, 0};
- //Purple orange yellow colors
- // Gradient palette "bhw2_xc_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xc.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 28 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bhw2_xc_gp ) {
- 0, 4, 2, 9,
- 58, 16, 0, 47,
- 122, 24, 0, 16,
- 158, 144, 9, 1,
- 183, 179, 45, 1,
- 219, 220,114, 2,
- 255, 234,237, 1};
- //Yellow orange purple blue
- // Gradient palette "bhw1_04_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_04.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 20 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bhw1_04_gp ) {
- 0, 229,227, 1,
- 15, 227,101, 3,
- 142, 40, 1, 80,
- 198, 17, 1, 79,
- 255, 0, 0, 45};
- //blue and yellow
- // Gradient palette "bhw4_051_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw4/tn/bhw4_051.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 36 bytes of program space.
- //More thanksgiving colors
- // Gradient palette "fs2006_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/cl/tn/fs2006.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 56 bytes of program space.
- DEFINE_GRADIENT_PALETTE( fs2006_gp ) {
- 0, 0, 49, 5,
- 34, 0, 49, 5,
- 34, 79,168, 66,
- 62, 79,168, 66,
- 62, 252,168, 92,
- 103, 252,168, 92,
- 103, 234, 81, 29,
- 143, 234, 81, 29,
- 143, 222, 30, 1,
- 184, 222, 30, 1,
- 184, 90, 13, 1,
- 238, 90, 13, 1,
- 238, 210, 1, 1,
- 255, 210, 1, 1};
- DEFINE_GRADIENT_PALETTE( bhw4_051_gp ) {
- 0, 1, 1, 4,
- 28, 16, 24, 77,
- 66, 35, 87,160,
- 101, 125,187,205,
- 127, 255,233, 13,
- 145, 125,187,205,
- 193, 28, 70,144,
- 224, 14, 19, 62,
- 255, 1, 1, 4};
- //dark blue light blue colors
- // Gradient palette "blue_g2_5_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/go2/webtwo/tn/blue-g2-5.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 16 bytes of program space.
- DEFINE_GRADIENT_PALETTE( blue_g2_5_gp ) {
- 0, 2, 6, 63,
- 127, 2, 9, 67,
- 255, 255, 255, 115,
- 255, 255, 255, 0};
- //Blue White Red colors
- // Gradient palette "bhw3_41_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw3/tn/bhw3_41.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 36 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bhw3_41_gp ) {
- 0, 0, 0, 45,
- 71, 7, 12,255,
- 76, 75, 91,255,
- 76, 255,255,255,
- 81, 255,255,255,
- 178, 255,255,255,
- 179, 255, 55, 45,
- 196, 255, 0, 0,
- 255, 42, 0, 0};
- DEFINE_GRADIENT_PALETTE( test_gp ) {
- 0, 255, 0, 0, // Red
- // 32, 171, 85, 0, // Orange
- // 64, 171,171, 0, // Yellow
- // 96, 0,255, 0, // Green
- //128, 0,171, 85, // Aqua
- 160, 0, 0,255, // Blue
- //192, 85, 0,171, // Purple
- //224, 171, 0, 85, // Pink
- //255, 255, 0, 0};// and back to Red
- };
- //Green colors
- // Gradient palette "bhw2_greenman_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_greenman.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 12 bytes of program space.
- DEFINE_GRADIENT_PALETTE( bhw2_greenman_gp ) {
- 0, 1, 22, 1,
- 130, 1,168, 2,
- 255, 1, 22, 1};
- //blue and yellow
- // Gradient palette "Pills_3_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/icons/tn/Pills-3.png.index.html
- // converted for FastLED with gammas (2.6, 2.2, 2.5)
- // Size: 12 bytes of program space.
- DEFINE_GRADIENT_PALETTE( Pills_3_gp ) {
- 0, 4, 12,122,
- 127, 55, 58, 50,
- 255, 192,147, 11};
- /****************************** MQTT TOPICS (change these topics as you wish) ***************************************/
- #define colorstatuspub "bruh/mqttstrip/colorstatus"
- #define setcolorsub "bruh/mqttstrip/setcolor"
- #define setpowersub "bruh/mqttstrip/setpower"
- #define seteffectsub "bruh/mqttstrip/seteffect"
- #define setbrightness "bruh/mqttstrip/setbrightness"
- #define setcolorpub "bruh/mqttstrip/setcolorpub"
- #define setpowerpub "bruh/mqttstrip/setpowerpub"
- #define seteffectpub "bruh/mqttstrip/seteffectpub"
- #define setbrightnesspub "bruh/mqttstrip/setbrightnesspub"
- #define setanimationspeed "bruh/mqttstrip/setanimationspeed"
- /*************************** EFFECT CONTROL VARIABLES AND INITIALIZATIONS ************************************/
- #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
- #warning "Requires FastLED 3.1 or later; check github for latest code."
- #endif
- String setColor ="0,0,150";
- String setPower;
- String setEffect = "Solid";
- String setBrightness = "150";
- int brightness = 150;
- String setAnimationSpeed;
- int animationspeed = 240;
- String setColorTemp;
- int Rcolor = 0;
- int Gcolor = 0;
- int Bcolor = 0;
- CRGB leds[NUM_LEDS];
- TBlendType currentBlending;
- /****************FOR CANDY CANE-like desings***************/
- CRGBPalette16 currentPalettestriped; //for Candy Cane
- CRGBPalette16 RGWPalettestriped; //for Red Green White
- CRGBPalette16 RGPalettestriped; //for Red Green Glitter
- CRGBPalette16 hailPalettestriped; //for Hail
- CRGBPalette16 ThxPalettestriped; //for Thanksgiving
- CRGBPalette16 HalloweenPalettestriped; //for Halloween Purple and Orange EFFECT
- CRGBPalette16 Halloween2Palettestriped; //for Halloween Orange and Green EFFECT
- CRGBPalette16 Halloween3Palettestriped; //for Halloween Purple and Green EFFECT
- CRGBPalette16 HalloweenTriPalettestriped; //for 3 color Halloween Purple, Orange and Green
- CRGBPalette16 PurpleGreenPalettestriped; //for Halloween Purple and Green
- CRGBPalette16 OrangeGreenPalettestriped; //for Halloween Orange and Green
- CRGBPalette16 OrangePurplePalettestriped; //for Halloween Orange and Green
- CRGBPalette16 CandyCornPalettestriped; //for Candy Corn
- CRGBPalette16 HJPalettestriped; //for Holly Jolly
- CRGBPalette16 IndPalettestriped; //for Independence
- CRGBPalette16 gPal; //for fire
- extern const TProgmemPalette16 myC9Palette PROGMEM;
- /****************FOR NOISE - I'm using this one for Easter***************/
- static uint16_t dist; // A random number for our noise generator.
- uint16_t scale = 30; // Wouldn't recommend changing this on the fly, or the animation will be really blocky.
- uint8_t maxChanges = 48; // Value for blending between palettes.
- CRGBPalette16 targetPalette(OceanColors_p);
- CRGBPalette16 currentPalette(CRGB::Black);
- uint8_t colorIndex;
- /*****************For TWINKLE********/
- #define DENSITY 80
- int twinklecounter = 0;
- /*********FOR RIPPLE***********/
- uint8_t colour; // Ripple colour is randomized.
- int center = 0; // Center of the current ripple.
- int step = -1; // -1 is the initializing step.
- uint8_t myfade = 255; // Starting brightness.
- #define maxsteps 16 // Case statement wouldn't allow a variable.
- uint8_t bgcol = 0; // Background colour rotates.
- int thisdelay = 20; // Standard delay value.
- /**************FOR RAINBOW***********/
- uint8_t thishue = 0; // Starting hue value.
- uint8_t deltahue = 10;
- /**************FOR DOTS**************/
- uint8_t count = 0; // Count up to 255 and then reverts to 0
- uint8_t fadeval = 224; // Trail behind the LED's. Lower => faster fade.
- uint8_t bpm = 30;
- /**************FOR LIGHTNING**************/
- uint8_t frequency = 75; // controls the interval between strikes
- uint8_t flashes = 8; //the upper limit of flashes per strike
- unsigned int dimmer = 1;
- uint8_t ledstart; // Starting location of a flash
- uint8_t ledlen;
- int lightningcounter = 0;
- /**************FOR STROBE**************/
- uint8_t strobeIntervalMs = 50; // controls the interval between strobe flashes
- CRGB strobeColor = CRGB::White; // the "on" color of the strobe
- /********FOR FUNKBOX EFFECTS**********/
- int idex = 0; //-LED INDEX (0 to NUM_LEDS-1
- int TOP_INDEX = int(NUM_LEDS / 2);
- int thissat = 255; //-FX LOOPS DELAY VAR
- //////////////////add thishue__ for Police All custom effects here/////////////////////////////////////////////////////////
- /////////////////use hsv Hue number for one color, for second color change "thishue__ + __" in the setEffect section//////
- uint8_t thishuepolice = 0;
- uint8_t thishuehail = 64;
- uint8_t thishueLovey = 0;
- uint8_t thishueHalloween = 28;
- uint8_t thishueHalloween2 = 28;
- uint8_t thishueHalloween3 = 96;
- int antipodal_index(int i) {
- int iN = i + TOP_INDEX;
- if (i >= TOP_INDEX) {
- iN = ( i + TOP_INDEX ) % NUM_LEDS;
- }
- return iN;
- }
- /********FIRE**********/
- #define COOLING 55
- #define SPARKING 120
- bool gReverseDirection = false;
- /********BPM**********/
- uint8_t gHue = 0;
- char message_buff[100];
- WiFiClient espArch;
- PubSubClient client(espArch);
- ////////////////////////////////////////////////////////////
- void setup() {
- WiFi.setSleepMode(WIFI_NONE_SLEEP);
- Serial.begin(115200);
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setMaxPowerInVoltsAndMilliamps(12, 10000); //experimental for power management. Feel free to try in your own setup.
- FastLED.setBrightness(brightness);
- setupStripedPalette( CRGB::Red, CRGB::Red, CRGB::White, CRGB::White); //for CANDY CANE
- setupRGWPalette( CRGB::Red, CRGB::White, CRGB::Green, CRGB::White); //for Red Green White
- setupRGPalette( CRGB::Red, CRGB::Green, CRGB::Red, CRGB::Green); //for Red Green
- setupThxPalette( CRGB::OrangeRed, CRGB::Olive, CRGB::Maroon, CRGB::Maroon); //for Thanksgiving
- setupHailPalette( CRGB::Blue, CRGB::Blue, CRGB::Yellow, CRGB::Yellow); //for HAIL
- setupHalloweenTriPalette( CRGB(255,95,0), CRGB(0,255,0), CRGB(115,0,235), CRGB::Black); //for Halloween Orange Green Purple
- setupOrangeGreenPalette( CRGB(255,95,0), CRGB(0,255,0), CRGB::Black, CRGB(0,255,0)); //for Halloween Orange & Green
- setupPurpleGreenPalette( CRGB(115,0,235), CRGB(0,255,0), CRGB::Black, CRGB(0,255,0)); //for Halloween Purple & Green
- setupOrangePurplePalette( CRGB(255,95,0), CRGB(115,0,235), CRGB::Black, CRGB(255,95,0)); //for Halloween Orange & Purple
- setupCandyCornPalette( CRGB(255,95,0), CRGB(240,240,0), CRGB(255,255,255), CRGB::Black); //for CandyCane Orange Yellow White
- setupHJPalette( CRGB::Red, CRGB::Red, CRGB::Green, CRGB::Green); //for Holly Jolly
- setupIndPalette( CRGB::Red, CRGB::White, CRGB::Blue, CRGB::MediumBlue); //for Independence
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- gPal = HeatColors_p; //for FIRE
- fill_solid(leds, NUM_LEDS, CRGB(255, 0, 0)); //Startup LED Lights
- FastLED.show();
- setup_wifi();
- client.setServer(mqtt_server, 1883); //CHANGE PORT HERE IF NEEDED
- client.setCallback(callback);
- //OTA SETUP
- ArduinoOTA.setPort(OTAport);
- // Hostname defaults to esp8266-[ChipID]
- ArduinoOTA.setHostname(SENSORNAME);
- // No authentication by default
- ArduinoOTA.setPassword((const char *)OTApassword);
- ArduinoOTA.onStart([]() {
- Serial.println("Starting");
- });
- ArduinoOTA.onEnd([]() {
- Serial.println("\nEnd");
- });
- ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
- });
- ArduinoOTA.onError([](ota_error_t error) {
- Serial.printf("Error[%u]: ", error);
- if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
- else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
- else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
- else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
- else if (error == OTA_END_ERROR) Serial.println("End Failed");
- });
- ArduinoOTA.begin();
- Serial.println("Ready");
- Serial.print("IP Address: ");
- Serial.println(WiFi.localIP());
- }
- void setup_wifi() {
- delay(10);
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(wifi_ssid);
- WiFi.mode(WIFI_STA);
- WiFi.begin(wifi_ssid, wifi_password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void callback(char* topic, byte* payload, unsigned int length) {
- int i = 0;
- if (String(topic) == setpowersub) {
- for (i = 0; i < length; i++) {
- message_buff[i] = payload[i];
- }
- message_buff[i] = '\0';
- setPower = String(message_buff);
- Serial.println("Set Power: " + setPower);
- if (setPower == "OFF") {
- client.publish(setpowerpub, "OFF");
- }
- if (setPower == "ON") {
- client.publish(setpowerpub, "ON");
- }
- }
- if (String(topic) == seteffectsub) {
- for (i = 0; i < length; i++) {
- message_buff[i] = payload[i];
- }
- message_buff[i] = '\0';
- setEffect = String(message_buff);
- Serial.println("Set Effect: " + setEffect);
- setPower = "ON";
- client.publish(setpowerpub, "ON");
- if (setEffect == "Twinkle") {
- twinklecounter = 0;
- }
- if (setEffect == "Lightning") {
- twinklecounter = 0;
- }
- }
- if (String(topic) == setbrightness) {
- for (i = 0; i < length; i++) {
- message_buff[i] = payload[i];
- }
- message_buff[i] = '\0';
- setBrightness = String(message_buff);
- Serial.println("Set Brightness: " + setBrightness);
- brightness = setBrightness.toInt();
- setPower = "ON";
- client.publish(setpowerpub, "ON");
- }
- if (String(topic) == setcolorsub) {
- for (i = 0; i < length; i++) {
- message_buff[i] = payload[i];
- }
- message_buff[i] = '\0';
- client.publish(setcolorpub, message_buff);
- setColor = String(message_buff);
- Serial.println("Set Color: " + setColor);
- setPower = "ON";
- client.publish(setpowerpub, "ON");
- }
- if (String(topic) == setanimationspeed) {
- for (i = 0; i < length; i++) {
- message_buff[i] = payload[i];
- }
- message_buff[i] = '\0';
- setAnimationSpeed = String(message_buff);
- animationspeed = setAnimationSpeed.toInt();
- }
- }
- void loop() {
- if (!client.connected()) {
- reconnect();
- }
- if (WiFi.status() != WL_CONNECTED) {
- delay(1);
- Serial.print("WIFI Disconnected. Attempting reconnection.");
- setup_wifi();
- return;
- }
- client.loop();
- ArduinoOTA.handle();
- int Rcolor = setColor.substring(0, setColor.indexOf(',')).toInt();
- int Gcolor = setColor.substring(setColor.indexOf(',') + 1, setColor.lastIndexOf(',')).toInt();
- int Bcolor = setColor.substring(setColor.lastIndexOf(',') + 1).toInt();
- if (setPower == "OFF") {
- setEffect = "Solid";
- for ( int i = 0; i < NUM_LEDS; i++) {
- leds[i].fadeToBlackBy( 8 ); //FADE OFF LEDS
- }
- }
- /////////////////////////////////////////
- //////DrZzs custom effects//////////////
- ///////////////////////////////////////
- if (setEffect == "Christmas") { // colored stripes pulsing in Shades of GREEN and RED
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = bhw2_xmas_gp;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- if (setEffect == "St Patty") { // colored stripes pulsing in Shades of GREEN
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = bhw2_greenman_gp;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- if (setEffect == "Valentine") { // colored stripes pulsing in Shades of PINK and RED
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = bhw2_redrosey_gp;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- if (setEffect == "Turkey Day") { // colored stripes pulsing in Shades of Brown and ORANGE
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = bhw2_thanks_gp;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- if (setEffect == "Thanksgiving") { // colored stripes pulsing in Shades of Red and ORANGE and Green
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- ThxPalettestriped, 255, LINEARBLEND);
- }
- if (setEffect == "USA") { // colored stripes pulsing in Shades of Red White & Blue
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = bhw3_41_gp;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- if (setEffect == "Independence") { // colored stripes of Red White & Blue
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- IndPalettestriped, 255, NOBLEND);
- }
- if (setEffect == "Go Blue") { // colored stripes pulsing in Shades of Maize and Blue
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = Pills_3_gp;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- if (setEffect == "Hail") {
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- hailPalettestriped, 255, LINEARBLEND);
- }
- if (setEffect == "Touchdown") { //Maize and Blue with POLICE ALL animation
- idex++;
- if (idex >= NUM_LEDS) {
- idex = 0;
- }
- int idexY = idex;
- int idexB = antipodal_index(idexY);
- int thathue = (thishuehail + 96) % 255;
- leds[idexY] = CHSV(thishuehail, thissat, 255);
- leds[idexB] = CHSV(thathue, thissat, 255);
- }
- if (setEffect == "Lovey Day") { //Valentine's Day colors (TWO COLOR SOLID)
- idex++;
- if (idex >= NUM_LEDS) {
- idex = 0;
- }
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishueLovey + 244) % 255;
- leds[idexR] = CHSV(thishueLovey, thissat, 255);
- leds[idexB] = CHSV(thathue, thissat, 255);
- }
- if (setEffect == "Holly Jolly") {
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- HJPalettestriped, 255, NOBLEND);
- }
- /////////////////End DrZzs effects/////////////
- ///////////////////////////////////////////////
- ////////My custom effects below////////////
- if (setEffect == "Strobe") {
- Strobe();
- }
- if (setEffect == "C9") {
- FillLEDsFromPaletteColors( colorIndex);
- }
- if (setEffect == "C9 Moving") {
- FillLEDsFromPaletteColors( colorIndex);
- colorIndex++;
- }
- if (setEffect == "Red Green White") { //Red Green and White
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- RGWPalettestriped, 255, NOBLEND);
- }
- if (setEffect == "Red Green With Glitter") { //Red Green colors with Glitter
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- RGPalettestriped, 255, NOBLEND);
- addGlitter(320);
- }
- if (setEffect == "Orange & Purple EFFECT") { //Orange and Purple colors (TWO COLOR SOLID)
- idex++;
- if (idex >= NUM_LEDS) {
- idex = 0;
- }
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishueHalloween + 170) % 255;
- leds[idexR] = CHSV(thishueHalloween, thissat, 255);
- leds[idexB] = CHSV(thathue, thissat, 255);
- }
- if (setEffect == "Orange & Green EFFECT") { //Orange and Green colors (TWO COLOR SOLID)
- idex++;
- if (idex >= NUM_LEDS) {
- idex = 0;
- }
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishueHalloween2 + 66) % 255;
- leds[idexR] = CHSV(thishueHalloween2, thissat, 255);
- leds[idexB] = CHSV(thathue, thissat, 255);
- }
- if (setEffect == "Purple & Green EFFECT") { //Purple and Green colors (TWO COLOR SOLID)
- idex++;
- if (idex >= NUM_LEDS) {
- idex = 0;
- }
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishueHalloween3 + 96) % 255;
- leds[idexR] = CHSV(thishueHalloween3, thissat, 255);
- leds[idexB] = CHSV(thathue, thissat, 255);
- }
- if (setEffect == "HalloweenTri") { //Orange Green and Purple
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- HalloweenTriPalettestriped, 255, NOBLEND);
- }
- if (setEffect == "Purple & Green") { //Purple and Green
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- PurpleGreenPalettestriped, 255, NOBLEND);
- }
- if (setEffect == "Orange & Green") { //Orange and Green
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- OrangeGreenPalettestriped, 255, NOBLEND);
- }
- if (setEffect == "Orange & Purple") { //Orange and Green
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- OrangePurplePalettestriped, 255, NOBLEND);
- }
- if (setEffect == "Candy Corn") { //Candy Corn theme
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- CandyCornPalettestriped, 255, NOBLEND);
- }
- /////////////end custom effects////////////////
- ///////////////////////////////////////////////
- /////////fastLED & Bruh effects///////////////
- /////////////////////////////////////////////
- if (setEffect == "Sinelon") {
- fadeToBlackBy( leds, NUM_LEDS, 20);
- int pos = beatsin16(13, 0, NUM_LEDS);
- leds[pos] += CRGB(Rcolor, Gcolor, Bcolor);
- }
- if (setEffect == "Juggle" ) { // eight colored dots, weaving in and out of sync with each other
- fadeToBlackBy( leds, NUM_LEDS, 20);
- byte dothue = 0;
- for ( int i = 0; i < 8; i++) {
- leds[beatsin16(i + 7, 0, NUM_LEDS)] |= CRGB(Rcolor, Gcolor, Bcolor);
- dothue += 32;
- }
- }
- if (setEffect == "Confetti" ) { // random colored speckles that blink in and fade smoothly
- fadeToBlackBy( leds, NUM_LEDS, 10);
- int pos = random16(NUM_LEDS);
- leds[pos] += CRGB(Rcolor + random8(64), Gcolor, Bcolor);
- }
- if (setEffect == "Rainbow") {
- // FastLED's built-in rainbow generator
- static uint8_t starthue = 0; thishue++;
- fill_rainbow(leds, NUM_LEDS, thishue, deltahue);
- }
- if (setEffect == "Rainbow with Glitter") { // FastLED's built-in rainbow generator with Glitter
- static uint8_t starthue = 0;
- thishue++;
- fill_rainbow(leds, NUM_LEDS, thishue, deltahue);
- addGlitter(80);
- }
- if (setEffect == "Glitter") {
- fadeToBlackBy( leds, NUM_LEDS, 20);
- addGlitterColor(80, Rcolor, Gcolor, Bcolor);
- }
- if (setEffect == "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, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- if (setEffect == "Solid" & setPower == "ON" ) { //Fill entire strand with solid color
- fill_solid(leds, NUM_LEDS, CRGB(Rcolor, Gcolor, Bcolor));
- }
- if (setEffect == "Twinkle") {
- twinklecounter = twinklecounter + 1;
- if (twinklecounter < 2) { //Resets strip if previous animation was running
- FastLED.clear();
- FastLED.show();
- }
- const CRGB lightcolor(8, 7, 1);
- for ( int i = 0; i < NUM_LEDS; i++) {
- if ( !leds[i]) continue; // skip black pixels
- if ( leds[i].r & 1) { // is red odd?
- leds[i] -= lightcolor; // darken if red is odd
- } else {
- leds[i] += lightcolor; // brighten if red is even
- }
- }
- if ( random8() < DENSITY) {
- int j = random16(NUM_LEDS);
- if ( !leds[j] ) leds[j] = lightcolor;
- }
- }
- if (setEffect == "Dots") {
- uint8_t inner = beatsin8(bpm, NUM_LEDS / 4, NUM_LEDS / 4 * 3);
- uint8_t outer = beatsin8(bpm, 0, NUM_LEDS - 1);
- uint8_t middle = beatsin8(bpm, NUM_LEDS / 3, NUM_LEDS / 3 * 2);
- leds[middle] = CRGB::Purple;
- leds[inner] = CRGB::Blue;
- leds[outer] = CRGB::Aqua;
- nscale8(leds, NUM_LEDS, fadeval);
- }
- if (setEffect == "Lightning") {
- twinklecounter = twinklecounter + 1; //Resets strip if previous animation was running
- Serial.println(twinklecounter);
- if (twinklecounter < 2) {
- FastLED.clear();
- FastLED.show();
- }
- ledstart = random8(NUM_LEDS); // Determine starting location of flash
- ledlen = random8(NUM_LEDS - ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
- for (int flashCounter = 0; flashCounter < random8(3, flashes); flashCounter++) {
- if (flashCounter == 0) dimmer = 5; // the brightness of the leader is scaled down by a factor of 5
- else dimmer = random8(1, 3); // return strokes are brighter than the leader
- fill_solid(leds + ledstart, ledlen, CHSV(255, 0, 255 / dimmer));
- FastLED.show(); // Show a section of LED's
- delay(random8(4, 10)); // each flash only lasts 4-10 milliseconds
- fill_solid(leds + ledstart, ledlen, CHSV(255, 0, 0)); // Clear the section of LED's
- FastLED.show();
- if (flashCounter == 0) delay (150); // longer delay until next flash after the leader
- delay(50 + random8(100)); // shorter delay between strokes
- }
- delay(random8(frequency) * 100); // delay between strikes
- }
- if (setEffect == "Police One") { //POLICE LIGHTS (TWO COLOR SINGLE LED)
- idex++;
- if (idex >= NUM_LEDS) {
- idex = 0;
- }
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishuepolice + 160) % 255;
- for (int i = 0; i < NUM_LEDS; i++ ) {
- if (i == idexR) {
- leds[i] = CHSV(thishuepolice, thissat, 255);
- }
- else if (i == idexB) {
- leds[i] = CHSV(thathue, thissat, 255);
- }
- else {
- leds[i] = CHSV(0, 0, 0);
- }
- }
- }
- if (setEffect == "Police All") { //POLICE LIGHTS (TWO COLOR SOLID)
- idex++;
- if (idex >= NUM_LEDS) {
- idex = 0;
- }
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishuepolice + 160) % 255;
- leds[idexR] = CHSV(thishuepolice, thissat, 255);
- leds[idexB] = CHSV(thathue, thissat, 255);
- }
- if (setEffect == "Candy Cane") {
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* higher = faster motion */
- fill_palette( leds, NUM_LEDS,
- startIndex, 16, /* higher = narrower stripes */
- currentPalettestriped, 255, LINEARBLEND);
- }
- if (setEffect == "Cyclon Rainbow") { //Single Dot Down
- static uint8_t hue = 0;
- Serial.print("x");
- // First slide the led in one direction
- for(int i = 0; i < NUM_LEDS; i++) {
- // Set the i'th led to red
- leds[i] = CHSV(hue++, 255, 255);
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- // leds[i] = CRGB::Black;
- fadeall();
- // Wait a little bit before we loop around and do it again
- delay(10);
- }
- for(int i = (NUM_LEDS)-1; i >= 0; i--) {
- // Set the i'th led to red
- leds[i] = CHSV(hue++, 255, 255);
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- // leds[i] = CRGB::Black;
- fadeall();
- // Wait a little bit before we loop around and do it again
- delay(10);
- }
- }
- if (setEffect == "Fire") {
- Fire2012WithPalette();
- }
- random16_add_entropy( random8());
- EVERY_N_MILLISECONDS(10) {
- nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // FOR NOISE ANIMATION
- { gHue++; }
- if (setEffect == "Easter") {
- setPower = "ON";
- for (int i = 0; i < NUM_LEDS; i++) { // Just ONE loop to fill up the LED array as all of the pixels change.
- uint8_t index = inoise8(i * scale, dist + i * scale) % 255; // Get a value from the noise function. I'm using both x and y axis.
- leds[i] = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // With that value, look up the 8 bit colour palette value and assign it to the current LED.
- }
- dist += beatsin8(10, 1, 4); // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
- // In some sketches, I've used millis() instead of an incremented counter. Works a treat.
- }
- if (setEffect == "Ripple") {
- for (int i = 0; i < NUM_LEDS; i++) leds[i] = CHSV(bgcol++, 255, 15); // Rotate background colour.
- switch (step) {
- case -1: // Initialize ripple variables.
- center = random(NUM_LEDS);
- colour = random8();
- step = 0;
- break;
- case 0:
- leds[center] = CHSV(colour, 255, 255); // Display the first pixel of the ripple.
- step ++;
- break;
- case maxsteps: // At the end of the ripples.
- step = -1;
- break;
- default: // Middle of the ripples.
- leds[(center + step + NUM_LEDS) % NUM_LEDS] += CHSV(colour, 255, myfade / step * 2); // Simple wrap from Marc Miller
- leds[(center - step + NUM_LEDS) % NUM_LEDS] += CHSV(colour, 255, myfade / step * 2);
- step ++; // Next step.
- break;
- }
- }
- }
- EVERY_N_SECONDS(5) {
- targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 255, random8(128, 255)), CHSV(random8(), 192, random8(128, 255)), CHSV(random8(), 255, random8(128, 255)));
- }
- FastLED.setBrightness(brightness); //EXECUTE EFFECT COLOR
- FastLED.show();
- if (animationspeed > 0 && animationspeed < 150) { //Sets animation speed based on receieved value
- FastLED.delay(1000 / animationspeed);
- }
- }
- ////////////////////////place setup__Palette and __Palettestriped custom functions here - for Candy Cane effects /////////////////
- ///////You can use up to 4 colors and change the pattern of A's AB's B's and BA's as you like//////////////
- void setupStripedPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- currentPalettestriped = CRGBPalette16(
- A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B
- );
- }
- void setupHailPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- hailPalettestriped = CRGBPalette16(
- A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B
- );
- }
- void setupHJPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- HJPalettestriped = CRGBPalette16(
- A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B
- );
- }
- void setupIndPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- IndPalettestriped = CRGBPalette16(
- A, A, A, A, A, AB, AB, AB, AB, AB, B, B, B, B, B, B
- );
- }
- void setupThxPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- ThxPalettestriped = CRGBPalette16(
- A, A, A, A, A, A, A, AB, AB, AB, B, B, B, B, B, B
- );
- }
- void setupHalloweenTriPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- HalloweenTriPalettestriped = CRGBPalette16(
- BA, A, A, A, BA, AB, AB, AB, BA, B, B, B, BA, AB, AB, AB
- );
- }
- void setupPurpleGreenPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- PurpleGreenPalettestriped = CRGBPalette16(
- B, A, A, A, B, AB, AB, AB, B, A, A, A, B, AB, AB, AB
- );
- }
- void setupOrangeGreenPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- OrangeGreenPalettestriped = CRGBPalette16(
- B, A, A, A, B, AB, AB, AB, B, A, A, A, B, AB, AB, AB
- );
- }
- void setupOrangePurplePalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- OrangePurplePalettestriped = CRGBPalette16(
- B, A, A, A, B, AB, AB, AB, B, A, A, A, B, AB, AB, AB
- );
- }
- void setupCandyCornPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- CandyCornPalettestriped = CRGBPalette16(
- BA, BA, B, AB, AB, A, A, A, BA, BA, B, AB, AB, A, A, A
- );
- }
- void setupRGWPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- RGWPalettestriped = CRGBPalette16(
- A, A, A, AB, AB, AB, B, B, B, A, A, A, AB, AB, AB, AB
- );
- }
- void setupRGPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
- {
- RGPalettestriped = CRGBPalette16(
- A, A, A, A, AB, AB, AB, AB, A, A, A, A, AB, AB, AB, AB
- );
- }
- ////////////////////////////////////////////////////////
- void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } } //for CYCLON
- void Fire2012WithPalette()
- {
- // Array of temperature readings at each simulation cell
- static byte heat[NUM_LEDS];
- // Step 1. Cool down every cell a little
- for( int i = 0; i < NUM_LEDS; i++) {
- heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
- }
- // Step 2. Heat from each cell drifts 'up' and diffuses a little
- for( int k= NUM_LEDS - 1; k >= 2; k--) {
- heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
- }
- // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- if( random8() < SPARKING ) {
- int y = random8(7);
- heat[y] = qadd8( heat[y], random8(160,255) );
- }
- // Step 4. Map from heat cells to LED colors
- for( int j = 0; j < NUM_LEDS; j++) {
- // Scale the heat value from 0-255 down to 0-240
- // for best results with color palettes.
- byte colorindex = scale8( heat[j], 240);
- CRGB color = ColorFromPalette( gPal, colorindex);
- int pixelnumber;
- if( gReverseDirection ) {
- pixelnumber = (NUM_LEDS-1) - j;
- } else {
- pixelnumber = j;
- }
- leds[pixelnumber] = color;
- }
- }
- const TProgmemPalette16 myC9Palette PROGMEM =
- {
- CRGB::Red,
- CRGB::DarkOrange,
- CRGB::Blue,
- CRGB::Green,
- CRGB::Yellow,
- CRGB::White,
- CRGB::Red,
- CRGB::DarkOrange,
- CRGB::Blue,
- CRGB::Green,
- CRGB::Yellow,
- CRGB::White,
- CRGB::Red,
- CRGB::DarkOrange,
- CRGB::Blue,
- CRGB::Green
- };
- void Strobe() {
- if ((millis() / strobeIntervalMs) % 2) {
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- } else {
- fill_solid(leds, NUM_LEDS, strobeColor);
- }
- }
- void FillLEDsFromPaletteColors( uint8_t colorIndex)
- {
- uint8_t brightness = 255;
- currentPalette = myC9Palette;
- currentBlending = NOBLEND;
- for( int i = 0; i < NUM_LEDS-1; i++) {
- leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, NOBLEND);
- colorIndex += 16;
- }
- }
- void addGlitter( fract8 chanceOfGlitter)
- {
- if( random8() < chanceOfGlitter) {
- leds[ random16(NUM_LEDS) ] += CRGB::White;
- }
- }
- void addGlitterColor( fract8 chanceOfGlitter, int Rcolor, int Gcolor, int Bcolor)
- {
- if( random8() < chanceOfGlitter) {
- leds[ random16(NUM_LEDS) ] += CRGB(Rcolor, Gcolor, Bcolor);
- }
- }
- void reconnect() {
- // Loop until we're reconnected
- while (!client.connected()) {
- Serial.print("Attempting MQTT connection...");
- // Attempt to connect
- if (client.connect("ArchLEDs", mqtt_user, mqtt_password)) {
- Serial.println("connected");
- FastLED.clear (); //Turns off startup LEDs after connection is made
- FastLED.show();
- client.subscribe(setcolorsub);
- client.subscribe(setbrightness);
- //client.subscribe(setcolortemp);
- client.subscribe(setpowersub);
- client.subscribe(seteffectsub);
- client.subscribe(setanimationspeed);
- client.publish(setpowerpub, "OFF");
- } else {
- Serial.print("failed, rc=");
- Serial.print(client.state());
- Serial.println(" try again in 5 seconds");
- // Wait 5 seconds before retrying
- delay(5000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement