Advertisement
Guest User

Untitled

a guest
Sep 4th, 2018
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 42.48 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <ESP8266WiFi.h>
  3. #include <PubSubClient.h>
  4. #define FASTLED_INTERRUPT_RETRY_COUNT 0
  5. #include <FastLED.h>
  6. #include <ArduinoOTA.h>
  7. #include <ESP8266mDNS.h>
  8. #include <WiFiUdp.h>
  9. /************ WIFI and MQTT INFORMATION (CHANGE THESE FOR YOUR SETUP) ******************/
  10. #define wifi_ssid "**" //enter your WIFI SSID
  11. #define wifi_password "**" //enter your WIFI Password
  12.  
  13. /**************************** FOR OTA **************************************************/
  14. #define SENSORNAME "Holiday LED Arduino" //change this to whatever you want to call your device
  15. #define OTApassword "**" //the password you will need to enter to upload remotely via the ArduinoIDE
  16. int OTAport = 8266;
  17.  
  18. #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
  19. #define mqtt_user "**" //enter your MQTT username
  20. #define mqtt_password "**" //enter your password
  21.  
  22. /************ FastLED Defintions ******************/
  23.  
  24. #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.
  25. #define LED_TYPE    WS2812B //change to match your LED type
  26. #define COLOR_ORDER GRB //change to match your LED configuration, ws2812 are GRB, 2811 are RGB
  27. #define NUM_LEDS    223 //change to match your setup, for multiple runs of LEDs use the number of the run with the most LEDs.
  28.  
  29. ///////////////DrZzs Palettes for custom BPM effects//////////////////////////
  30. ///////////////Add any custom palettes here//////////////////////////////////
  31.  
  32. //Thanksgiving colors
  33. // Gradient palette "bhw2_thanks_gp", originally from
  34. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_thanks.png.index.html
  35. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  36. // Size: 36 bytes of program space.
  37.  
  38. DEFINE_GRADIENT_PALETTE( bhw2_thanks_gp ) {
  39.     0,   9,  5,  1,
  40.    48,  25,  9,  1,
  41.    76, 137, 27,  1,
  42.    96,  98, 42,  1,
  43.   124, 144, 79,  1,
  44.   153,  98, 42,  1,
  45.   178, 137, 27,  1,
  46.   211,  23,  9,  1,
  47.   255,   9,  5,  1};
  48.  
  49. //Red/Pink colors
  50. // Gradient palette "bhw2_redrosey_gp", originally from
  51. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_redrosey.png.index.html
  52. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  53. // Size: 32 bytes of program space.
  54.  
  55. DEFINE_GRADIENT_PALETTE( bhw2_redrosey_gp ) {
  56.     0, 103,  1, 10,
  57.    33, 109,  1, 12,
  58.    76, 159,  5, 48,
  59.   119, 175, 55,103,
  60.   127, 175, 55,103,
  61.   178, 159,  5, 48,
  62.   221, 109,  1, 12,
  63.   255, 103,  1, 10};
  64.  
  65. //Blue to Red - has light blue white and pink
  66. // Gradient palette "bluered_gp", originally from
  67. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/h5/tn/bluered.png.index.html
  68. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  69. // Size: 12 bytes of program space.
  70.  
  71. DEFINE_GRADIENT_PALETTE( bluered_gp ) {
  72.     0,   0,  0,255,
  73.   127, 255,255,255,
  74.   255, 255,  0,  0};
  75.  
  76. //Green and Red
  77. // Gradient palette "bhw2_xmas_gp", originally from
  78. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xmas.png.index.html
  79. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  80. // Size: 48 bytes of program space.
  81.  
  82. DEFINE_GRADIENT_PALETTE( bhw2_xmas_gp ) {
  83.     0,   0, 12,  0,
  84.    40,   0, 55,  0,
  85.    66,   1,117,  2,
  86.    77,   1, 84,  1,
  87.    81,   0, 55,  0,
  88.   119,   0, 12,  0,
  89.   153,  42,  0,  0,
  90.   181, 121,  0,  0,
  91.   204, 255, 12,  8,
  92.   224, 121,  0,  0,
  93.   244,  42,  0,  0,
  94.   255,  42,  0,  0};
  95.  
  96. //Purple orange yellow colors
  97. // Gradient palette "bhw2_xc_gp", originally from
  98. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xc.png.index.html
  99. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  100. // Size: 28 bytes of program space.
  101.  
  102. DEFINE_GRADIENT_PALETTE( bhw2_xc_gp ) {
  103.     0,   4,  2,  9,
  104.    58,  16,  0, 47,
  105.   122,  24,  0, 16,
  106.   158, 144,  9,  1,
  107.   183, 179, 45,  1,
  108.   219, 220,114,  2,
  109.   255, 234,237,  1};
  110.  
  111. //Yellow orange purple blue
  112. // Gradient palette "bhw1_04_gp", originally from
  113. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_04.png.index.html
  114. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  115. // Size: 20 bytes of program space.
  116.  
  117. DEFINE_GRADIENT_PALETTE( bhw1_04_gp ) {
  118.     0, 229,227,  1,
  119.    15, 227,101,  3,
  120.   142,  40,  1, 80,
  121.   198,  17,  1, 79,
  122.   255,   0,  0, 45};
  123.  
  124. //blue and yellow
  125. // Gradient palette "bhw4_051_gp", originally from
  126. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw4/tn/bhw4_051.png.index.html
  127. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  128. // Size: 36 bytes of program space.
  129.  
  130. //More thanksgiving colors
  131. // Gradient palette "fs2006_gp", originally from
  132. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/cl/tn/fs2006.png.index.html
  133. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  134. // Size: 56 bytes of program space.
  135.  
  136. DEFINE_GRADIENT_PALETTE( fs2006_gp ) {
  137.     0,   0, 49,  5,
  138.    34,   0, 49,  5,
  139.    34,  79,168, 66,
  140.    62,  79,168, 66,
  141.    62, 252,168, 92,
  142.   103, 252,168, 92,
  143.   103, 234, 81, 29,
  144.   143, 234, 81, 29,
  145.   143, 222, 30,  1,
  146.   184, 222, 30,  1,
  147.   184,  90, 13,  1,
  148.   238,  90, 13,  1,
  149.   238, 210,  1,  1,
  150.   255, 210,  1,  1};
  151.  
  152.  
  153. DEFINE_GRADIENT_PALETTE( bhw4_051_gp ) {
  154.     0,   1,  1,  4,
  155.    28,  16, 24, 77,
  156.    66,  35, 87,160,
  157.   101, 125,187,205,
  158.   127, 255,233, 13,
  159.   145, 125,187,205,
  160.   193,  28, 70,144,
  161.   224,  14, 19, 62,
  162.   255,   1,  1,  4};
  163.  
  164. //dark blue light blue colors
  165. // Gradient palette "blue_g2_5_gp", originally from
  166. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/go2/webtwo/tn/blue-g2-5.png.index.html
  167. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  168. // Size: 16 bytes of program space.
  169.  
  170. DEFINE_GRADIENT_PALETTE( blue_g2_5_gp ) {
  171.     0,   2,  6, 63,
  172.   127,   2,  9, 67,
  173.   255,   255, 255, 115,
  174.   255,   255, 255, 0};
  175.  
  176. //Blue White Red colors
  177. // Gradient palette "bhw3_41_gp", originally from
  178. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw3/tn/bhw3_41.png.index.html
  179. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  180. // Size: 36 bytes of program space.
  181.  
  182. DEFINE_GRADIENT_PALETTE( bhw3_41_gp ) {
  183.     0,   0,  0, 45,
  184.    71,   7, 12,255,
  185.    76,  75, 91,255,
  186.    76, 255,255,255,
  187.    81, 255,255,255,
  188.   178, 255,255,255,
  189.   179, 255, 55, 45,
  190.   196, 255,  0,  0,
  191.   255,  42,  0,  0};
  192.  
  193. DEFINE_GRADIENT_PALETTE( test_gp ) {
  194.     0,  255,  0,  0, // Red
  195. // 32,  171, 85,  0, // Orange
  196. // 64,  171,171,  0, // Yellow
  197. // 96,    0,255,  0, // Green
  198. //128,    0,171, 85, // Aqua
  199.   160,    0,  0,255, // Blue
  200. //192,   85,  0,171, // Purple
  201. //224,  171,  0, 85, // Pink
  202. //255,  255,  0,  0};// and back to Red
  203. };  
  204.  
  205. //Green colors
  206. // Gradient palette "bhw2_greenman_gp", originally from
  207. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_greenman.png.index.html
  208. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  209. // Size: 12 bytes of program space.
  210.  
  211. DEFINE_GRADIENT_PALETTE( bhw2_greenman_gp ) {
  212.     0,   1, 22,  1,
  213.   130,   1,168,  2,
  214.   255,   1, 22,  1};
  215.  
  216. //blue and yellow
  217. // Gradient palette "Pills_3_gp", originally from
  218. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/icons/tn/Pills-3.png.index.html
  219. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  220. // Size: 12 bytes of program space.
  221.  
  222. DEFINE_GRADIENT_PALETTE( Pills_3_gp ) {
  223.     0,   4, 12,122,
  224.   127,  55, 58, 50,
  225.   255, 192,147, 11};
  226.  
  227. /****************************** MQTT TOPICS (change these topics as you wish)  ***************************************/
  228.  
  229. #define colorstatuspub "bruh/mqttstrip/colorstatus"
  230. #define setcolorsub "bruh/mqttstrip/setcolor"
  231. #define setpowersub "bruh/mqttstrip/setpower"
  232. #define seteffectsub "bruh/mqttstrip/seteffect"
  233. #define setbrightness "bruh/mqttstrip/setbrightness"
  234.  
  235. #define setcolorpub "bruh/mqttstrip/setcolorpub"
  236. #define setpowerpub "bruh/mqttstrip/setpowerpub"
  237. #define seteffectpub "bruh/mqttstrip/seteffectpub"
  238. #define setbrightnesspub "bruh/mqttstrip/setbrightnesspub"
  239. #define setanimationspeed "bruh/mqttstrip/setanimationspeed"
  240.  
  241. /*************************** EFFECT CONTROL VARIABLES AND INITIALIZATIONS ************************************/
  242.  
  243. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  244. #warning "Requires FastLED 3.1 or later; check github for latest code."
  245. #endif
  246.  
  247. String setColor ="0,0,150";
  248. String setPower;
  249. String setEffect = "Solid";
  250. String setBrightness = "150";
  251. int brightness = 150;
  252. String setAnimationSpeed;
  253. int animationspeed = 240;
  254. String setColorTemp;
  255. int Rcolor = 0;
  256. int Gcolor = 0;
  257. int Bcolor = 0;
  258. CRGB leds[NUM_LEDS];
  259.  
  260. TBlendType    currentBlending;
  261.  
  262. /****************FOR CANDY CANE-like desings***************/
  263. CRGBPalette16 currentPalettestriped; //for Candy Cane
  264. CRGBPalette16 RGWPalettestriped; //for Red Green White
  265. CRGBPalette16 RGPalettestriped; //for Red Green Glitter
  266. CRGBPalette16 hailPalettestriped; //for Hail
  267. CRGBPalette16 ThxPalettestriped; //for Thanksgiving
  268. CRGBPalette16 HalloweenPalettestriped; //for Halloween Purple and Orange EFFECT
  269. CRGBPalette16 Halloween2Palettestriped; //for Halloween Orange and Green EFFECT
  270. CRGBPalette16 Halloween3Palettestriped; //for Halloween Purple and Green EFFECT
  271. CRGBPalette16 HalloweenTriPalettestriped; //for 3 color Halloween Purple, Orange and Green
  272. CRGBPalette16 PurpleGreenPalettestriped; //for Halloween Purple and Green
  273. CRGBPalette16 OrangeGreenPalettestriped; //for Halloween Orange and Green
  274. CRGBPalette16 OrangePurplePalettestriped; //for Halloween Orange and Green
  275. CRGBPalette16 CandyCornPalettestriped; //for Candy Corn
  276. CRGBPalette16 HJPalettestriped; //for Holly Jolly
  277. CRGBPalette16 IndPalettestriped; //for Independence
  278. CRGBPalette16 gPal; //for fire
  279. extern const TProgmemPalette16 myC9Palette PROGMEM;
  280.  
  281. /****************FOR NOISE - I'm using this one for Easter***************/
  282. static uint16_t dist;         // A random number for our noise generator.
  283. uint16_t scale = 30;          // Wouldn't recommend changing this on the fly, or the animation will be really blocky.
  284. uint8_t maxChanges = 48;      // Value for blending between palettes.
  285. CRGBPalette16 targetPalette(OceanColors_p);
  286. CRGBPalette16 currentPalette(CRGB::Black);
  287. uint8_t colorIndex;
  288.  
  289. /*****************For TWINKLE********/
  290. #define DENSITY     80
  291. int twinklecounter = 0;
  292.  
  293. /*********FOR RIPPLE***********/
  294. uint8_t colour;                                               // Ripple colour is randomized.
  295. int center = 0;                                               // Center of the current ripple.
  296. int step = -1;                                                // -1 is the initializing step.
  297. uint8_t myfade = 255;                                         // Starting brightness.
  298. #define maxsteps 16                                           // Case statement wouldn't allow a variable.
  299. uint8_t bgcol = 0;                                            // Background colour rotates.
  300. int thisdelay = 20;                                           // Standard delay value.
  301.  
  302. /**************FOR RAINBOW***********/
  303. uint8_t thishue = 0;                                          // Starting hue value.
  304. uint8_t deltahue = 10;
  305.  
  306. /**************FOR DOTS**************/
  307. uint8_t   count =   0;                                        // Count up to 255 and then reverts to 0
  308. uint8_t fadeval = 224;                                        // Trail behind the LED's. Lower => faster fade.
  309. uint8_t bpm = 30;
  310.  
  311. /**************FOR LIGHTNING**************/
  312. uint8_t frequency = 75;                                       // controls the interval between strikes
  313. uint8_t flashes = 8;                                          //the upper limit of flashes per strike
  314. unsigned int dimmer = 1;
  315. uint8_t ledstart;                                             // Starting location of a flash
  316. uint8_t ledlen;
  317. int lightningcounter = 0;
  318.  
  319. /**************FOR STROBE**************/
  320. uint8_t strobeIntervalMs = 50;                                // controls the interval between strobe flashes
  321. CRGB strobeColor = CRGB::White;                               // the "on" color of the strobe
  322.  
  323. /********FOR FUNKBOX EFFECTS**********/
  324. int idex = 0;                //-LED INDEX (0 to NUM_LEDS-1
  325. int TOP_INDEX = int(NUM_LEDS / 2);
  326. int thissat = 255;           //-FX LOOPS DELAY VAR
  327.  
  328. //////////////////add thishue__ for Police All custom effects here/////////////////////////////////////////////////////////
  329. /////////////////use hsv Hue number for one color, for second color change "thishue__ + __" in the setEffect section//////
  330.  
  331. uint8_t thishuepolice = 0;
  332. uint8_t thishuehail = 64;
  333. uint8_t thishueLovey = 0;
  334. uint8_t thishueHalloween = 28;  
  335. uint8_t thishueHalloween2 = 28;
  336. uint8_t thishueHalloween3 = 96;    
  337. int antipodal_index(int i) {
  338.   int iN = i + TOP_INDEX;
  339.   if (i >= TOP_INDEX) {
  340.     iN = ( i + TOP_INDEX ) % NUM_LEDS;
  341.   }
  342.   return iN;
  343. }
  344.  
  345. /********FIRE**********/
  346. #define COOLING  55
  347. #define SPARKING 120
  348. bool gReverseDirection = false;
  349.  
  350. /********BPM**********/
  351. uint8_t gHue = 0;
  352. char message_buff[100];
  353.  
  354.  
  355. WiFiClient espArch;
  356. PubSubClient client(espArch);
  357.  
  358. ////////////////////////////////////////////////////////////
  359.  
  360. void setup() {
  361.   WiFi.setSleepMode(WIFI_NONE_SLEEP);
  362.   Serial.begin(115200);
  363.  
  364.   FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  365.   FastLED.setMaxPowerInVoltsAndMilliamps(12, 10000); //experimental for power management. Feel free to try in your own setup.
  366.   FastLED.setBrightness(brightness);
  367.  
  368.   setupStripedPalette( CRGB::Red, CRGB::Red, CRGB::White, CRGB::White); //for CANDY CANE
  369.   setupRGWPalette( CRGB::Red, CRGB::White, CRGB::Green, CRGB::White); //for Red Green White
  370.   setupRGPalette( CRGB::Red, CRGB::Green, CRGB::Red, CRGB::Green); //for Red Green
  371.   setupThxPalette( CRGB::OrangeRed, CRGB::Olive, CRGB::Maroon, CRGB::Maroon); //for Thanksgiving
  372.   setupHailPalette( CRGB::Blue, CRGB::Blue, CRGB::Yellow, CRGB::Yellow); //for HAIL
  373.   setupHalloweenTriPalette( CRGB(255,95,0), CRGB(0,255,0), CRGB(115,0,235), CRGB::Black); //for Halloween Orange Green Purple
  374.   setupOrangeGreenPalette( CRGB(255,95,0), CRGB(0,255,0), CRGB::Black, CRGB(0,255,0)); //for Halloween Orange & Green
  375.   setupPurpleGreenPalette( CRGB(115,0,235), CRGB(0,255,0), CRGB::Black, CRGB(0,255,0)); //for Halloween Purple & Green
  376.   setupOrangePurplePalette( CRGB(255,95,0), CRGB(115,0,235), CRGB::Black, CRGB(255,95,0)); //for Halloween Orange & Purple
  377.   setupCandyCornPalette( CRGB(255,95,0), CRGB(240,240,0), CRGB(255,255,255), CRGB::Black); //for CandyCane Orange Yellow White
  378.   setupHJPalette( CRGB::Red, CRGB::Red, CRGB::Green, CRGB::Green); //for Holly Jolly
  379.   setupIndPalette( CRGB::Red, CRGB::White, CRGB::Blue, CRGB::MediumBlue); //for Independence
  380.  
  381. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  382.  
  383.   gPal = HeatColors_p; //for FIRE
  384.  
  385.   fill_solid(leds, NUM_LEDS, CRGB(255, 0, 0)); //Startup LED Lights
  386.   FastLED.show();
  387.  
  388.   setup_wifi();
  389.  
  390.   client.setServer(mqtt_server, 1883); //CHANGE PORT HERE IF NEEDED
  391.   client.setCallback(callback);
  392.  
  393.     //OTA SETUP
  394.   ArduinoOTA.setPort(OTAport);
  395.   // Hostname defaults to esp8266-[ChipID]
  396.   ArduinoOTA.setHostname(SENSORNAME);
  397.  
  398.   // No authentication by default
  399.   ArduinoOTA.setPassword((const char *)OTApassword);
  400.  
  401.   ArduinoOTA.onStart([]() {
  402.     Serial.println("Starting");
  403.   });
  404.   ArduinoOTA.onEnd([]() {
  405.     Serial.println("\nEnd");
  406.   });
  407.   ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  408.     Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  409.   });
  410.   ArduinoOTA.onError([](ota_error_t error) {
  411.     Serial.printf("Error[%u]: ", error);
  412.     if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  413.     else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  414.     else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  415.     else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  416.     else if (error == OTA_END_ERROR) Serial.println("End Failed");
  417.   });
  418.   ArduinoOTA.begin();
  419.  
  420.   Serial.println("Ready");
  421.   Serial.print("IP Address: ");
  422.   Serial.println(WiFi.localIP());
  423. }
  424.  
  425.  
  426. void setup_wifi() {
  427.  
  428.   delay(10);
  429.   Serial.println();
  430.   Serial.print("Connecting to ");
  431.   Serial.println(wifi_ssid);
  432.  
  433.   WiFi.mode(WIFI_STA);
  434.   WiFi.begin(wifi_ssid, wifi_password);
  435.  
  436.   while (WiFi.status() != WL_CONNECTED) {
  437.     delay(500);
  438.     Serial.print(".");
  439.   }
  440.  
  441.   Serial.println("");
  442.   Serial.println("WiFi connected");
  443.   Serial.println("IP address: ");
  444.   Serial.println(WiFi.localIP());
  445. }
  446.  
  447. void callback(char* topic, byte* payload, unsigned int length) {
  448.   int i = 0;
  449.  
  450.   if (String(topic) == setpowersub) {
  451.     for (i = 0; i < length; i++) {
  452.       message_buff[i] = payload[i];
  453.     }
  454.     message_buff[i] = '\0';
  455.     setPower = String(message_buff);
  456.     Serial.println("Set Power: " + setPower);
  457.     if (setPower == "OFF") {
  458.       client.publish(setpowerpub, "OFF");
  459.     }
  460.  
  461.     if (setPower == "ON") {
  462.       client.publish(setpowerpub, "ON");
  463.     }
  464.   }
  465.  
  466.  
  467.   if (String(topic) == seteffectsub) {
  468.     for (i = 0; i < length; i++) {
  469.       message_buff[i] = payload[i];
  470.     }
  471.     message_buff[i] = '\0';
  472.     setEffect = String(message_buff);
  473.     Serial.println("Set Effect: " + setEffect);
  474.     setPower = "ON";
  475.     client.publish(setpowerpub, "ON");
  476.     if (setEffect == "Twinkle") {
  477.       twinklecounter = 0;
  478.     }
  479.     if (setEffect == "Lightning") {
  480.       twinklecounter = 0;
  481.     }
  482.   }
  483.  
  484.  
  485.   if (String(topic) == setbrightness) {
  486.     for (i = 0; i < length; i++) {
  487.       message_buff[i] = payload[i];
  488.     }
  489.     message_buff[i] = '\0';
  490.     setBrightness = String(message_buff);
  491.     Serial.println("Set Brightness: " + setBrightness);
  492.     brightness = setBrightness.toInt();
  493.     setPower = "ON";
  494.     client.publish(setpowerpub, "ON");
  495.   }
  496.  
  497.   if (String(topic) == setcolorsub) {
  498.     for (i = 0; i < length; i++) {
  499.       message_buff[i] = payload[i];
  500.     }
  501.     message_buff[i] = '\0';
  502.     client.publish(setcolorpub, message_buff);
  503.     setColor = String(message_buff);
  504.     Serial.println("Set Color: " + setColor);
  505.     setPower = "ON";
  506.     client.publish(setpowerpub, "ON");
  507.     }
  508.  
  509.   if (String(topic) == setanimationspeed) {
  510.     for (i = 0; i < length; i++) {
  511.       message_buff[i] = payload[i];
  512.     }
  513.     message_buff[i] = '\0';
  514.     setAnimationSpeed = String(message_buff);
  515.     animationspeed = setAnimationSpeed.toInt();
  516.   }
  517. }
  518.  
  519.  
  520.  
  521. void loop() {
  522.  
  523.  if (!client.connected()) {
  524.     reconnect();
  525.   }
  526.  
  527.   if (WiFi.status() != WL_CONNECTED) {
  528.     delay(1);
  529.     Serial.print("WIFI Disconnected. Attempting reconnection.");
  530.     setup_wifi();
  531.     return;
  532.   }
  533.  
  534.  
  535.  
  536.   client.loop();
  537.  
  538.   ArduinoOTA.handle();
  539.  
  540.  
  541.   int Rcolor = setColor.substring(0, setColor.indexOf(',')).toInt();
  542.   int Gcolor = setColor.substring(setColor.indexOf(',') + 1, setColor.lastIndexOf(',')).toInt();
  543.   int Bcolor = setColor.substring(setColor.lastIndexOf(',') + 1).toInt();
  544.  
  545.   if (setPower == "OFF") {
  546.     setEffect = "Solid";
  547.     for ( int i = 0; i < NUM_LEDS; i++) {
  548.       leds[i].fadeToBlackBy( 8 );   //FADE OFF LEDS
  549.     }
  550.   }
  551.  
  552. /////////////////////////////////////////  
  553. //////DrZzs custom effects//////////////
  554. ///////////////////////////////////////
  555.  
  556.   if (setEffect == "Christmas") {                                  // colored stripes pulsing in Shades of GREEN and RED
  557.     uint8_t BeatsPerMinute = 62;
  558.     CRGBPalette16 palette = bhw2_xmas_gp;
  559.     uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  560.     for( int i = 0; i < NUM_LEDS; i++) { //9948
  561.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  562.   }
  563. }
  564.  
  565.   if (setEffect == "St Patty") {                                  // colored stripes pulsing in Shades of GREEN
  566.     uint8_t BeatsPerMinute = 62;
  567.     CRGBPalette16 palette = bhw2_greenman_gp;
  568.     uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  569.     for( int i = 0; i < NUM_LEDS; i++) { //9948
  570.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  571.   }
  572. }
  573.  
  574.   if (setEffect == "Valentine") {                                  // colored stripes pulsing in Shades of PINK and RED
  575.     uint8_t BeatsPerMinute = 62;
  576.     CRGBPalette16 palette = bhw2_redrosey_gp;
  577.     uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  578.     for( int i = 0; i < NUM_LEDS; i++) { //9948
  579.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  580.   }
  581. }
  582.  
  583.   if (setEffect == "Turkey Day") {                                  // colored stripes pulsing in Shades of Brown and ORANGE
  584.     uint8_t BeatsPerMinute = 62;
  585.     CRGBPalette16 palette = bhw2_thanks_gp;
  586.     uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  587.     for( int i = 0; i < NUM_LEDS; i++) { //9948
  588.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  589.   }
  590. }
  591.  
  592.   if (setEffect == "Thanksgiving") {                                  // colored stripes pulsing in Shades of Red and ORANGE and Green
  593.     static uint8_t startIndex = 0;
  594.     startIndex = startIndex + 1; /* higher = faster motion */
  595.  
  596.     fill_palette( leds, NUM_LEDS,
  597.                   startIndex, 16, /* higher = narrower stripes */
  598.                   ThxPalettestriped, 255, LINEARBLEND);
  599. }
  600.  
  601.   if (setEffect == "USA") {                                  // colored stripes pulsing in Shades of Red White & Blue
  602.     uint8_t BeatsPerMinute = 62;
  603.     CRGBPalette16 palette = bhw3_41_gp;
  604.     uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  605.     for( int i = 0; i < NUM_LEDS; i++) { //9948
  606.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  607.   }
  608. }
  609.  
  610.   if (setEffect == "Independence") {                        // colored stripes of Red White & Blue
  611.     static uint8_t startIndex = 0;
  612.     startIndex = startIndex + 1; /* higher = faster motion */
  613.  
  614.     fill_palette( leds, NUM_LEDS,
  615.                   startIndex, 16, /* higher = narrower stripes */
  616.                   IndPalettestriped, 255, NOBLEND);
  617. }
  618.  
  619.     if (setEffect == "Go Blue") {                                  // colored stripes pulsing in Shades of Maize and Blue
  620.     uint8_t BeatsPerMinute = 62;
  621.     CRGBPalette16 palette = Pills_3_gp;
  622.     uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  623.     for( int i = 0; i < NUM_LEDS; i++) { //9948
  624.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  625.   }
  626. }
  627.  
  628.   if (setEffect == "Hail") {
  629.     static uint8_t startIndex = 0;
  630.     startIndex = startIndex + 1; /* higher = faster motion */
  631.  
  632.     fill_palette( leds, NUM_LEDS,
  633.                   startIndex, 16, /* higher = narrower stripes */
  634.                   hailPalettestriped, 255, LINEARBLEND);
  635. }
  636.  
  637.   if (setEffect == "Touchdown") {                 //Maize and Blue with POLICE ALL animation
  638.     idex++;
  639.     if (idex >= NUM_LEDS) {
  640.       idex = 0;
  641.     }
  642.     int idexY = idex;
  643.     int idexB = antipodal_index(idexY);
  644.     int thathue = (thishuehail + 96) % 255;
  645.     leds[idexY] = CHSV(thishuehail, thissat, 255);
  646.     leds[idexB] = CHSV(thathue, thissat, 255);
  647.   }
  648.  
  649.     if (setEffect == "Lovey Day") {                 //Valentine's Day colors (TWO COLOR SOLID)
  650.     idex++;
  651.     if (idex >= NUM_LEDS) {
  652.       idex = 0;
  653.     }
  654.     int idexR = idex;
  655.     int idexB = antipodal_index(idexR);
  656.     int thathue = (thishueLovey + 244) % 255;
  657.     leds[idexR] = CHSV(thishueLovey, thissat, 255);
  658.     leds[idexB] = CHSV(thathue, thissat, 255);
  659.   }
  660.  
  661.   if (setEffect == "Holly Jolly") {
  662.     static uint8_t startIndex = 0;
  663.     startIndex = startIndex + 1; /* higher = faster motion */
  664.  
  665.     fill_palette( leds, NUM_LEDS,
  666.                   startIndex, 16, /* higher = narrower stripes */
  667.                   HJPalettestriped, 255, NOBLEND);
  668.   }
  669.  
  670. /////////////////End DrZzs effects/////////////
  671. ///////////////////////////////////////////////
  672.  
  673. ////////My custom effects below////////////
  674. if (setEffect == "Strobe") {
  675.   Strobe();
  676. }
  677.     if (setEffect == "C9") {  
  678.  FillLEDsFromPaletteColors( colorIndex);
  679. }
  680.  
  681. if (setEffect == "C9 Moving") {  
  682.  FillLEDsFromPaletteColors( colorIndex);
  683.   colorIndex++;
  684. }
  685.  
  686.       if (setEffect == "Red Green White") {     //Red Green and White
  687.     static uint8_t startIndex = 0;
  688.     startIndex = startIndex + 1; /* higher = faster motion */
  689.  
  690.     fill_palette( leds, NUM_LEDS,
  691.                   startIndex, 16, /* higher = narrower stripes */
  692.                   RGWPalettestriped, 255, NOBLEND);
  693.   }
  694.  
  695.  
  696.       if (setEffect == "Red Green With Glitter") {      //Red Green colors with Glitter
  697.     static uint8_t startIndex = 0;
  698.     startIndex = startIndex + 1; /* higher = faster motion */
  699.  
  700.     fill_palette( leds, NUM_LEDS,
  701.                   startIndex, 16, /* higher = narrower stripes */
  702.                   RGPalettestriped, 255, NOBLEND);
  703.                   addGlitter(320);
  704.   }
  705.  
  706.       if (setEffect == "Orange & Purple EFFECT") {                 //Orange and Purple colors (TWO COLOR SOLID)
  707.     idex++;
  708.     if (idex >= NUM_LEDS) {
  709.       idex = 0;
  710.     }
  711.     int idexR = idex;
  712.     int idexB = antipodal_index(idexR);
  713.     int thathue = (thishueHalloween + 170) % 255;
  714.     leds[idexR] = CHSV(thishueHalloween, thissat, 255);
  715.     leds[idexB] = CHSV(thathue, thissat, 255);
  716.   }
  717.  
  718.       if (setEffect == "Orange & Green EFFECT") {                 //Orange and Green colors (TWO COLOR SOLID)
  719.     idex++;
  720.     if (idex >= NUM_LEDS) {
  721.       idex = 0;
  722.     }
  723.     int idexR = idex;
  724.     int idexB = antipodal_index(idexR);
  725.     int thathue = (thishueHalloween2 + 66) % 255;
  726.     leds[idexR] = CHSV(thishueHalloween2, thissat, 255);
  727.     leds[idexB] = CHSV(thathue, thissat, 255);
  728.   }
  729.  
  730.       if (setEffect == "Purple & Green EFFECT") {                 //Purple and Green colors (TWO COLOR SOLID)
  731.     idex++;
  732.     if (idex >= NUM_LEDS) {
  733.       idex = 0;
  734.     }
  735.     int idexR = idex;
  736.     int idexB = antipodal_index(idexR);
  737.     int thathue = (thishueHalloween3 + 96) % 255;
  738.     leds[idexR] = CHSV(thishueHalloween3, thissat, 255);
  739.     leds[idexB] = CHSV(thathue, thissat, 255);
  740.   }
  741.  
  742.     if (setEffect == "HalloweenTri") {       //Orange Green and Purple
  743.     static uint8_t startIndex = 0;
  744.     startIndex = startIndex + 1; /* higher = faster motion */
  745.  
  746.     fill_palette( leds, NUM_LEDS,
  747.                   startIndex, 16, /* higher = narrower stripes */
  748.                   HalloweenTriPalettestriped, 255, NOBLEND);
  749.   }
  750.  
  751.       if (setEffect == "Purple & Green") {       //Purple and Green
  752.     static uint8_t startIndex = 0;
  753.     startIndex = startIndex + 1; /* higher = faster motion */
  754.  
  755.     fill_palette( leds, NUM_LEDS,
  756.                   startIndex, 16, /* higher = narrower stripes */
  757.                   PurpleGreenPalettestriped, 255, NOBLEND);
  758.   }
  759.  
  760.       if (setEffect == "Orange & Green") {       //Orange and Green
  761.     static uint8_t startIndex = 0;
  762.     startIndex = startIndex + 1; /* higher = faster motion */
  763.  
  764.     fill_palette( leds, NUM_LEDS,
  765.                   startIndex, 16, /* higher = narrower stripes */
  766.                   OrangeGreenPalettestriped, 255, NOBLEND);
  767.   }
  768.  
  769.         if (setEffect == "Orange & Purple") {       //Orange and Green
  770.     static uint8_t startIndex = 0;
  771.     startIndex = startIndex + 1; /* higher = faster motion */
  772.  
  773.     fill_palette( leds, NUM_LEDS,
  774.                   startIndex, 16, /* higher = narrower stripes */
  775.                   OrangePurplePalettestriped, 255, NOBLEND);
  776.   }
  777.  
  778.     if (setEffect == "Candy Corn") {      //Candy Corn theme
  779.     static uint8_t startIndex = 0;
  780.     startIndex = startIndex + 1; /* higher = faster motion */
  781.  
  782.     fill_palette( leds, NUM_LEDS,
  783.                   startIndex, 16, /* higher = narrower stripes */
  784.                   CandyCornPalettestriped, 255, NOBLEND);
  785.   }
  786.  
  787.  
  788. /////////////end custom effects////////////////
  789.  
  790. ///////////////////////////////////////////////
  791. /////////fastLED & Bruh effects///////////////
  792. /////////////////////////////////////////////
  793.  
  794.   if (setEffect == "Sinelon") {
  795.     fadeToBlackBy( leds, NUM_LEDS, 20);
  796.     int pos = beatsin16(13, 0, NUM_LEDS);
  797.     leds[pos] += CRGB(Rcolor, Gcolor, Bcolor);
  798.   }
  799.  
  800.   if (setEffect == "Juggle" ) {                           // eight colored dots, weaving in and out of sync with each other
  801.     fadeToBlackBy( leds, NUM_LEDS, 20);
  802.     byte dothue = 0;
  803.     for ( int i = 0; i < 8; i++) {
  804.       leds[beatsin16(i + 7, 0, NUM_LEDS)] |= CRGB(Rcolor, Gcolor, Bcolor);
  805.       dothue += 32;
  806.     }
  807.   }
  808.  
  809.   if (setEffect == "Confetti" ) {                       // random colored speckles that blink in and fade smoothly
  810.     fadeToBlackBy( leds, NUM_LEDS, 10);
  811.     int pos = random16(NUM_LEDS);
  812.     leds[pos] += CRGB(Rcolor + random8(64), Gcolor, Bcolor);
  813.   }
  814.  
  815.  
  816.   if (setEffect == "Rainbow") {
  817.     // FastLED's built-in rainbow generator
  818.     static uint8_t starthue = 0;    thishue++;
  819.     fill_rainbow(leds, NUM_LEDS, thishue, deltahue);
  820.   }
  821.  
  822.  
  823.   if (setEffect == "Rainbow with Glitter") {               // FastLED's built-in rainbow generator with Glitter
  824.     static uint8_t starthue = 0;
  825.     thishue++;
  826.     fill_rainbow(leds, NUM_LEDS, thishue, deltahue);
  827.     addGlitter(80);
  828.   }
  829.  
  830.  
  831.  
  832.   if (setEffect == "Glitter") {
  833.     fadeToBlackBy( leds, NUM_LEDS, 20);
  834.     addGlitterColor(80, Rcolor, Gcolor, Bcolor);
  835.   }
  836.  
  837.  
  838.   if (setEffect == "BPM") {                                  // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  839.   uint8_t BeatsPerMinute = 62;
  840.   CRGBPalette16 palette = PartyColors_p;
  841.   uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  842.   for( int i = 0; i < NUM_LEDS; i++) { //9948
  843.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  844.   }
  845. }
  846.  
  847.   if (setEffect == "Solid" & setPower == "ON" ) {          //Fill entire strand with solid color
  848.     fill_solid(leds, NUM_LEDS, CRGB(Rcolor, Gcolor, Bcolor));
  849.   }
  850.  
  851.  
  852.  
  853.   if (setEffect == "Twinkle") {
  854.     twinklecounter = twinklecounter + 1;
  855.     if (twinklecounter < 2) {                               //Resets strip if previous animation was running
  856.       FastLED.clear();
  857.       FastLED.show();
  858.     }
  859.     const CRGB lightcolor(8, 7, 1);
  860.     for ( int i = 0; i < NUM_LEDS; i++) {
  861.       if ( !leds[i]) continue; // skip black pixels
  862.       if ( leds[i].r & 1) { // is red odd?
  863.         leds[i] -= lightcolor; // darken if red is odd
  864.       } else {
  865.         leds[i] += lightcolor; // brighten if red is even
  866.       }
  867.     }
  868.     if ( random8() < DENSITY) {
  869.       int j = random16(NUM_LEDS);
  870.       if ( !leds[j] ) leds[j] = lightcolor;
  871.     }
  872.   }
  873.  
  874.   if (setEffect == "Dots") {
  875.     uint8_t inner = beatsin8(bpm, NUM_LEDS / 4, NUM_LEDS / 4 * 3);
  876.     uint8_t outer = beatsin8(bpm, 0, NUM_LEDS - 1);
  877.     uint8_t middle = beatsin8(bpm, NUM_LEDS / 3, NUM_LEDS / 3 * 2);
  878.     leds[middle] = CRGB::Purple;
  879.     leds[inner] = CRGB::Blue;
  880.     leds[outer] = CRGB::Aqua;
  881.     nscale8(leds, NUM_LEDS, fadeval);
  882.   }
  883.  
  884.   if (setEffect == "Lightning") {
  885.     twinklecounter = twinklecounter + 1;                     //Resets strip if previous animation was running
  886.     Serial.println(twinklecounter);
  887.     if (twinklecounter < 2) {
  888.       FastLED.clear();
  889.       FastLED.show();
  890.     }
  891.     ledstart = random8(NUM_LEDS);           // Determine starting location of flash
  892.     ledlen = random8(NUM_LEDS - ledstart);  // Determine length of flash (not to go beyond NUM_LEDS-1)
  893.     for (int flashCounter = 0; flashCounter < random8(3, flashes); flashCounter++) {
  894.       if (flashCounter == 0) dimmer = 5;    // the brightness of the leader is scaled down by a factor of 5
  895.       else dimmer = random8(1, 3);          // return strokes are brighter than the leader
  896.       fill_solid(leds + ledstart, ledlen, CHSV(255, 0, 255 / dimmer));
  897.       FastLED.show();                       // Show a section of LED's
  898.       delay(random8(4, 10));                // each flash only lasts 4-10 milliseconds
  899.       fill_solid(leds + ledstart, ledlen, CHSV(255, 0, 0)); // Clear the section of LED's
  900.       FastLED.show();
  901.       if (flashCounter == 0) delay (150);   // longer delay until next flash after the leader
  902.       delay(50 + random8(100));             // shorter delay between strokes
  903.     }
  904.     delay(random8(frequency) * 100);        // delay between strikes
  905.   }
  906.  
  907.  
  908.  
  909.   if (setEffect == "Police One") {                    //POLICE LIGHTS (TWO COLOR SINGLE LED)
  910.     idex++;
  911.     if (idex >= NUM_LEDS) {
  912.       idex = 0;
  913.     }
  914.     int idexR = idex;
  915.     int idexB = antipodal_index(idexR);
  916.     int thathue = (thishuepolice + 160) % 255;
  917.     for (int i = 0; i < NUM_LEDS; i++ ) {
  918.       if (i == idexR) {
  919.         leds[i] = CHSV(thishuepolice, thissat, 255);
  920.       }
  921.       else if (i == idexB) {
  922.         leds[i] = CHSV(thathue, thissat, 255);
  923.       }
  924.       else {
  925.         leds[i] = CHSV(0, 0, 0);
  926.       }
  927.     }
  928.  
  929.   }
  930.  
  931.   if (setEffect == "Police All") {                 //POLICE LIGHTS (TWO COLOR SOLID)
  932.     idex++;
  933.     if (idex >= NUM_LEDS) {
  934.       idex = 0;
  935.     }
  936.     int idexR = idex;
  937.     int idexB = antipodal_index(idexR);
  938.     int thathue = (thishuepolice + 160) % 255;
  939.     leds[idexR] = CHSV(thishuepolice, thissat, 255);
  940.     leds[idexB] = CHSV(thathue, thissat, 255);
  941.   }
  942.  
  943.  
  944.   if (setEffect == "Candy Cane") {
  945.     static uint8_t startIndex = 0;
  946.     startIndex = startIndex + 1; /* higher = faster motion */
  947.  
  948.     fill_palette( leds, NUM_LEDS,
  949.                   startIndex, 16, /* higher = narrower stripes */
  950.                   currentPalettestriped, 255, LINEARBLEND);
  951.   }
  952.  
  953.  
  954.   if (setEffect == "Cyclon Rainbow") {                    //Single Dot Down
  955.   static uint8_t hue = 0;
  956.   Serial.print("x");
  957.   // First slide the led in one direction
  958.   for(int i = 0; i < NUM_LEDS; i++) {
  959.     // Set the i'th led to red
  960.     leds[i] = CHSV(hue++, 255, 255);
  961.     // Show the leds
  962.     FastLED.show();
  963.     // now that we've shown the leds, reset the i'th led to black
  964.     // leds[i] = CRGB::Black;
  965.     fadeall();
  966.     // Wait a little bit before we loop around and do it again
  967.     delay(10);
  968.   }
  969.   for(int i = (NUM_LEDS)-1; i >= 0; i--) {
  970.     // Set the i'th led to red
  971.     leds[i] = CHSV(hue++, 255, 255);
  972.     // Show the leds
  973.     FastLED.show();
  974.     // now that we've shown the leds, reset the i'th led to black
  975.     // leds[i] = CRGB::Black;
  976.     fadeall();
  977.     // Wait a little bit before we loop around and do it again
  978.     delay(10);
  979.   }
  980. }
  981.  
  982.   if (setEffect == "Fire") {
  983.       Fire2012WithPalette();
  984.   }
  985.      random16_add_entropy( random8());
  986.  
  987.  
  988.  
  989.  
  990.   EVERY_N_MILLISECONDS(10) {
  991.     nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges);  // FOR NOISE ANIMATION
  992.     { gHue++; }
  993.  
  994.  
  995.     if (setEffect == "Easter") {
  996.       setPower = "ON";
  997.       for (int i = 0; i < NUM_LEDS; i++) {                                     // Just ONE loop to fill up the LED array as all of the pixels change.
  998.         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.
  999.         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.
  1000.       }
  1001.       dist += beatsin8(10, 1, 4);                                              // Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
  1002.       // In some sketches, I've used millis() instead of an incremented counter. Works a treat.
  1003.     }
  1004.  
  1005.  
  1006.     if (setEffect == "Ripple") {
  1007.       for (int i = 0; i < NUM_LEDS; i++) leds[i] = CHSV(bgcol++, 255, 15);  // Rotate background colour.
  1008.       switch (step) {
  1009.         case -1:                                                          // Initialize ripple variables.
  1010.           center = random(NUM_LEDS);
  1011.           colour = random8();
  1012.           step = 0;
  1013.           break;
  1014.         case 0:
  1015.           leds[center] = CHSV(colour, 255, 255);                          // Display the first pixel of the ripple.
  1016.           step ++;
  1017.           break;
  1018.         case maxsteps:                                                    // At the end of the ripples.
  1019.           step = -1;
  1020.           break;
  1021.         default:                                                             // Middle of the ripples.
  1022.           leds[(center + step + NUM_LEDS) % NUM_LEDS] += CHSV(colour, 255, myfade / step * 2);   // Simple wrap from Marc Miller
  1023.           leds[(center - step + NUM_LEDS) % NUM_LEDS] += CHSV(colour, 255, myfade / step * 2);
  1024.           step ++;                                                         // Next step.
  1025.           break;
  1026.       }
  1027.     }
  1028.  
  1029.    
  1030.   }
  1031.  
  1032.   EVERY_N_SECONDS(5) {
  1033.     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)));
  1034.   }
  1035.  
  1036.   FastLED.setBrightness(brightness);  //EXECUTE EFFECT COLOR
  1037.   FastLED.show();
  1038.  
  1039.   if (animationspeed > 0 && animationspeed < 150) {  //Sets animation speed based on receieved value
  1040.     FastLED.delay(1000 / animationspeed);
  1041.   }
  1042.  
  1043. }
  1044.  
  1045.  
  1046. ////////////////////////place setup__Palette and __Palettestriped custom functions here - for Candy Cane effects /////////////////
  1047. ///////You can use up to 4 colors and change the pattern of A's AB's B's and BA's as you like//////////////
  1048.  
  1049. void setupStripedPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1050. {
  1051.   currentPalettestriped = CRGBPalette16(
  1052.                             A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B
  1053.                           );
  1054. }
  1055.  
  1056. void setupHailPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1057. {
  1058.   hailPalettestriped = CRGBPalette16(
  1059.                             A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B
  1060.                           );
  1061. }
  1062.  
  1063. void setupHJPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1064. {
  1065.   HJPalettestriped = CRGBPalette16(
  1066.                             A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B
  1067.                           );
  1068. }
  1069.  
  1070. void setupIndPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1071. {
  1072.   IndPalettestriped = CRGBPalette16(
  1073.                             A, A, A, A, A, AB, AB, AB, AB, AB, B, B, B, B, B, B
  1074.                           );
  1075. }
  1076.  
  1077. void setupThxPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1078. {
  1079.   ThxPalettestriped = CRGBPalette16(
  1080.                             A, A, A, A, A, A, A, AB, AB, AB, B, B, B, B, B, B
  1081.                           );
  1082. }
  1083.  
  1084. void setupHalloweenTriPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1085. {
  1086.   HalloweenTriPalettestriped = CRGBPalette16(
  1087.                             BA, A, A, A, BA, AB, AB, AB, BA, B, B, B, BA, AB, AB, AB
  1088.                           );
  1089. }
  1090.  
  1091. void setupPurpleGreenPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1092. {
  1093.   PurpleGreenPalettestriped = CRGBPalette16(
  1094.                             B, A, A, A, B, AB, AB, AB, B, A, A, A, B, AB, AB, AB
  1095.                           );
  1096. }
  1097.  
  1098. void setupOrangeGreenPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1099. {
  1100.   OrangeGreenPalettestriped = CRGBPalette16(
  1101.                               B, A, A, A, B, AB, AB, AB, B, A, A, A, B, AB, AB, AB
  1102.                           );
  1103. }
  1104.  
  1105. void setupOrangePurplePalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1106. {
  1107.   OrangePurplePalettestriped = CRGBPalette16(
  1108.                               B, A, A, A, B, AB, AB, AB, B, A, A, A, B, AB, AB, AB
  1109.                           );
  1110. }
  1111.  
  1112. void setupCandyCornPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1113. {
  1114.   CandyCornPalettestriped = CRGBPalette16(
  1115.                             BA, BA, B, AB, AB, A, A, A, BA, BA, B, AB, AB, A, A, A
  1116.                           );
  1117. }
  1118.  
  1119. void setupRGWPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1120. {
  1121.   RGWPalettestriped = CRGBPalette16(
  1122.                             A, A, A, AB, AB, AB, B, B, B, A, A, A, AB, AB, AB, AB
  1123.                           );
  1124. }
  1125.  
  1126. void setupRGPalette( CRGB A, CRGB AB, CRGB B, CRGB BA)
  1127. {
  1128.   RGPalettestriped = CRGBPalette16(
  1129.                             A, A, A, A, AB, AB, AB, AB, A, A, A, A, AB, AB, AB, AB
  1130.                           );
  1131. }
  1132.  
  1133. ////////////////////////////////////////////////////////
  1134.  
  1135. void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } } //for CYCLON
  1136.  
  1137.  
  1138. void Fire2012WithPalette()
  1139. {
  1140. // Array of temperature readings at each simulation cell
  1141.   static byte heat[NUM_LEDS];
  1142.  
  1143.   // Step 1.  Cool down every cell a little
  1144.     for( int i = 0; i < NUM_LEDS; i++) {
  1145.       heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
  1146.     }
  1147.  
  1148.     // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  1149.     for( int k= NUM_LEDS - 1; k >= 2; k--) {
  1150.       heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  1151.     }
  1152.    
  1153.     // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  1154.     if( random8() < SPARKING ) {
  1155.       int y = random8(7);
  1156.       heat[y] = qadd8( heat[y], random8(160,255) );
  1157.     }
  1158.  
  1159.     // Step 4.  Map from heat cells to LED colors
  1160.     for( int j = 0; j < NUM_LEDS; j++) {
  1161.       // Scale the heat value from 0-255 down to 0-240
  1162.       // for best results with color palettes.
  1163.       byte colorindex = scale8( heat[j], 240);
  1164.       CRGB color = ColorFromPalette( gPal, colorindex);
  1165.       int pixelnumber;
  1166.       if( gReverseDirection ) {
  1167.         pixelnumber = (NUM_LEDS-1) - j;
  1168.       } else {
  1169.         pixelnumber = j;
  1170.       }
  1171.       leds[pixelnumber] = color;
  1172.     }
  1173. }
  1174.  
  1175. const TProgmemPalette16 myC9Palette PROGMEM =
  1176. {
  1177.     CRGB::Red,
  1178.     CRGB::DarkOrange,
  1179.     CRGB::Blue,
  1180.     CRGB::Green,
  1181.    
  1182.     CRGB::Yellow,
  1183.     CRGB::White,
  1184.     CRGB::Red,
  1185.     CRGB::DarkOrange,
  1186.    
  1187.     CRGB::Blue,
  1188.     CRGB::Green,
  1189.     CRGB::Yellow,
  1190.     CRGB::White,
  1191.     CRGB::Red,
  1192.     CRGB::DarkOrange,
  1193.     CRGB::Blue,
  1194.     CRGB::Green
  1195. };
  1196.  
  1197. void Strobe() {
  1198.   if ((millis() / strobeIntervalMs) % 2) {
  1199.     fill_solid(leds, NUM_LEDS, CRGB::Black);
  1200.   } else {
  1201.     fill_solid(leds, NUM_LEDS, strobeColor);
  1202.   }
  1203. }
  1204.  
  1205. void FillLEDsFromPaletteColors( uint8_t colorIndex)
  1206. {
  1207.     uint8_t brightness = 255;
  1208.     currentPalette = myC9Palette;
  1209.     currentBlending = NOBLEND;
  1210.  
  1211.  
  1212.     for( int i = 0; i < NUM_LEDS-1; i++) {
  1213.         leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, NOBLEND);
  1214.         colorIndex += 16;
  1215.     }
  1216. }
  1217.  
  1218. void addGlitter( fract8 chanceOfGlitter)
  1219. {
  1220.   if( random8() < chanceOfGlitter) {
  1221.     leds[ random16(NUM_LEDS) ] += CRGB::White;
  1222.   }
  1223. }
  1224.  
  1225. void addGlitterColor( fract8 chanceOfGlitter, int Rcolor, int Gcolor, int Bcolor)
  1226. {
  1227.   if( random8() < chanceOfGlitter) {
  1228.     leds[ random16(NUM_LEDS) ] += CRGB(Rcolor, Gcolor, Bcolor);
  1229.   }
  1230. }
  1231.  
  1232.  
  1233. void reconnect() {
  1234.   // Loop until we're reconnected
  1235.   while (!client.connected()) {
  1236.     Serial.print("Attempting MQTT connection...");
  1237.     // Attempt to connect
  1238.   if (client.connect("ArchLEDs", mqtt_user, mqtt_password)) {
  1239.       Serial.println("connected");
  1240.  
  1241.       FastLED.clear (); //Turns off startup LEDs after connection is made
  1242.       FastLED.show();
  1243.  
  1244.       client.subscribe(setcolorsub);
  1245.       client.subscribe(setbrightness);
  1246.       //client.subscribe(setcolortemp);
  1247.       client.subscribe(setpowersub);
  1248.       client.subscribe(seteffectsub);
  1249.       client.subscribe(setanimationspeed);
  1250.       client.publish(setpowerpub, "OFF");
  1251.     } else {
  1252.       Serial.print("failed, rc=");
  1253.       Serial.print(client.state());
  1254.       Serial.println(" try again in 5 seconds");
  1255.       // Wait 5 seconds before retrying
  1256.       delay(5000);
  1257.     }
  1258.   }
  1259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement