Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FASTLED_INTERRUPT_RETRY_COUNT 0
- // #define FASTLED_ESP8266_RAW_PIN_ORDER
- /****************** LIBRARY SECTION *************************************/
- #include <FastLED.h> //https://github.com/FastLED/FastLED
- #include <SimpleTimer.h> //https://github.com/thehookup/Simple-Timer-Library
- #include <PubSubClient.h> //https://github.com/knolleary/pubsubclient
- #include <ESP8266WiFi.h> //if you get an error here you need to install the ESP8266 board manager
- #include <ESP8266mDNS.h> //if you get an error here you need to install the ESP8266 board manager
- #include <ArduinoOTA.h> //ArduinoOTA is now included with the ArduinoIDE
- #include <ESP8266WebServer.h>
- #include <ESP8266HTTPUpdateServer.h>
- #include <WiFiUdp.h>
- /***************** START USER CONFIG SECTION *********************************/
- /***************** START USER CONFIG SECTION *********************************/
- /***************** START USER CONFIG SECTION *********************************/
- /***************** START USER CONFIG SECTION *********************************/
- #define USER_SSID "XXXXXXXXXXXXXXX"
- #define USER_PASSWORD "XXXXXXXXXXXXXXX"
- #define USER_MQTT_SERVER "XXXXXXXXXXXXXXX"
- #define USER_MQTT_PORT 0000
- #define USER_MQTT_USERNAME "XXXXXXXXXX"
- #define USER_MQTT_PASSWORD "XXXXXXXXXXX"
- #define USER_MQTT_CLIENT_NAME "LightMCU" // Used to define MQTT topics, MQTT Client ID, and ArduinoOTA
- #define CHIPSET WS2811
- #define COLOR_ORDER GRB
- // const int pgLights = 4; //marked as D2 on the board
- // const int paLights = 5; //marked as D1 on the board
- // const int ggLights = 14; //marked as D5 on the board
- // const int gaLights = 12; //marked as D6 on the board
- #define MAXNUMLEDS 300 // Largest String of Leds
- #define NUMZONES 4 // Number of separate zones
- #define MAXSECTIONS 2 // Of all the Zones, most number of sections
- struct CRGB leds[NUMZONES][MAXNUMLEDS]; // Main LED array
- int numleds[NUMZONES] = {271, // Length of each string of leds
- 285, // Length of each string of leds
- 265, // Length of each string of leds
- 208 // Length of each string of leds
- }; // additional as necessary
- int sections[NUMZONES][MAXSECTIONS + 2] = { // first entry is number of sections. Subsequent entries are START indecies for sections
- { 2, // Number of Sections in this Zone
- 0, 137, 272
- }, // Not pretty, but start led for each section and then an extra value which is (length of string + 1)
- { 1, // Number of Sections in this Zone
- 0, 286, 286
- }, // Not pretty, but start led for each section and then an extra value which is (length of string + 1)
- { 2, // Number of Sections in this Zone
- 0, 134, 266
- }, // Not pretty, but start led for each section and then an extra value which is (length of string + 1)
- { 1, // Number of Sections in this Zone
- 0, 209, 209
- }
- }; // Not pretty, but start led for each section and then an extra value which is (length of string + 1)
- int firestarters[NUMZONES][2 * MAXSECTIONS] = { // Whether or not to start fire for start/end of each section
- {1, 0, 0, 1}, // (Start,End) per section
- {1, 1, 0, 0}, // (Start,End) per section
- {1, 0, 0, 1}, // (Start,End) per section
- {1, 1, 0, 0} // (Start,End) per section
- };
- // Add necessary terms based on NUMZONES
- int step[NUMZONES] = { -1, -1, -1, -1}; // Used in Ripple
- int lightning[NUMZONES] = {1, 1, 1, 1}; // Used in add Lightning
- // For fire I like to adjust size based on portion of roof. Bigger flames on A-Frame, less than 50% for flat sections as fire burns from both sides
- int firesize[NUMZONES] = {100, 40, 100, 40};
- // No need to edit
- int idex[NUMZONES] = {0}; //Used in Police
- int previousLED[NUMZONES] = {0} ; // Used in Single Race
- int center[NUMZONES] = {0}; // Used in Ripple
- /***************** END USER CONFIG SECTION *********************************/
- /***************** Color Setup *********************************/
- // Inspired by Dr Zzs Color setup
- ///////////////DrZzs Palettes for custom BPM effects//////////////////////////
- ///////////////Add any custom palettes here//////////////////////////////////
- // Sam Comments: Use PaletteKnife Booklet to convert cpt-city pages to Gradient Palettes
- /*
- Using PaletteKnife
- Go to cpt-city here, http://soliton.vm.bytemark.co.uk/pub/cpt-city/
- Find a palette you like, e.g. http://soliton.vm.bytemark.co.uk/pub/cpt-city/rc/tn/purplefly.png.index.html
- Click PaletteKnife in your toolbar. If you get warnings, choose a different palette and try again.
- Copy the resulting code and paste it into your source file.
- */
- // Brown to Orange
- // 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
- };
- DEFINE_GRADIENT_PALETTE( blue_gp ) {
- 0, 0, 0, 0,
- 64, 7, 18, 115,
- 128, 13, 35, 228,
- 192, 116, 130, 255,
- 255, 255, 255, 255
- };
- // Red to Pink
- // Gradient palette "bhw2_redrosey_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_redrosey.png.index.html
- // Red to Green
- // Gradient palette "bhw2_xmas_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_xmas.png.index.html
- // Purple to Yellow// 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 Fa
- // Yellow to 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
- // Blue Yellow Blue
- // Gradient palette "bhw4_051_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw4/tn/bhw4_051.png.index.html
- // Color of Cartoon Turkey Feathers
- // Gradient palette "fs2006_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/cl/tn/fs2006.png.index.html
- // 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( turkey_feathers_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};
- // 2 Shades of Blue
- // 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
- // Blue White Red
- // Gradient palette "bhw3_41_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw3/tn/bhw3_41.png.index.html
- // Green
- // Gradient palette "bhw2_greenman_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw2/tn/bhw2_greenman.png.index.html
- // Blue and GoldGradient
- // Gradient palette "Pills_3_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/icons/tn/Pills-3.png.index.html
- // Orange to Purple
- // Gradient palette "Orange_to_Purple_gp", originally from
- // http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/icons/tn/Orange-to-Purple.png.index.html
- CRGBPalette16 setupABStripedPalette( CRGB A, CRGB B)
- {
- return CRGBPalette16(
- A, A, A, A, A, A, A, A, B, B, B, B, B, B, B, B
- );
- }
- CRGBPalette16 setupABCStripedPalette( CRGB A, CRGB B, CRGB C)
- {
- return CRGBPalette16(
- A, A, A, A, A, B, B, B, B, B, C, C, C, C, C, C
- );
- }
- CRGBPalette16 setupAbCStripedPalette( CRGB A, CRGB b, CRGB C)
- {
- return CRGBPalette16(
- A, A, A, A, A, A, A, b, b, b, C, C, C, C, C, C
- );
- }
- CRGBPalette16 setupABCDStripedPalette( CRGB A, CRGB B, CRGB C, CRGB D)
- {
- return CRGBPalette16(
- A, A, A, A, B, B, B, B, C, C, C, C, D, D, D, D
- );
- }
- /***************** end Arrays ****************************************/
- /***************** GENERAL VARIABLES *************************************/
- CRGBPalette16 gPal;
- int glitterFrequency = 100;
- int lightningChance = 65280;
- int SPARKING = 85;
- int COOLING = 120;
- bool gReverseDirection = false;
- uint8_t mark = 0;
- uint8_t gHue = 0;
- uint8_t startPosition = 0;
- uint8_t glitterChance = 250;
- int chaseDelay = 1000;
- int lastPosition = 1;
- int raceSpeed = 12;
- int BeatsPerMinute = 62;
- uint8_t numberOfRainbows = 7;
- int twinkleChance = 250;
- int eyeChance = 248;
- bool boot = true;
- String effect = "None";
- String scene = "None";
- bool showGlitter = false;
- bool showLightning = false;
- bool audioEffects = false;
- bool showLights = false;
- byte red1 = 255;
- byte green1 = 0;
- byte blue1 = 0;
- byte red2 = 0;
- byte green2 = 255;
- byte blue2 = 0;
- byte red3 = 0;
- byte green3 = 0;
- byte blue3 = 255;
- byte redG = 255;
- byte greenG = 255;
- byte blueG = 255;
- byte brightness = 255;
- char charPayload[50];
- int maxLEDs = 300;
- int locatorLED = 0;
- char MQTT_locatorLED[50];
- int locatorDelay = 1000;
- // ********************************************* WIFI Setup **********************************
- const char* ssid = USER_SSID ;
- const char* password = USER_PASSWORD ;
- const char* mqtt_server = USER_MQTT_SERVER ;
- const int mqtt_port = USER_MQTT_PORT ;
- const char *mqtt_user = USER_MQTT_USERNAME ;
- const char *mqtt_pass = USER_MQTT_PASSWORD ;
- const char *mqtt_client_name = USER_MQTT_CLIENT_NAME ;
- SimpleTimer timer;
- /***************** DECLARATIONS ****************************************/
- WiFiClient espClient;
- PubSubClient client(espClient);
- ESP8266WebServer server(80);
- ESP8266HTTPUpdateServer httpUpdater;
- const char* serverIndex = "<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>";
- /*********************** WIFI AND MQTT SETUP *****************************/
- void led_wifi()
- {
- //For the life of me I can't get OTA to work with Google Wifi or something else about my setup so I added WebUploader
- /**** Need to call this from setup() just below setup_wifi below and add to loop() the following *******/
- /**** server.handleClient(); *******/
- /**** MDNS.update(); *******/
- httpUpdater.setup(&server);
- server.begin();
- MDNS.begin(USER_MQTT_CLIENT_NAME);
- server.on("/", HTTP_GET, []() {
- server.sendHeader("Connection", "close");
- server.send(200, "text/html", serverIndex);
- });
- server.on("/update", HTTP_POST, []() {
- server.sendHeader("Connection", "close");
- server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
- ESP.restart();
- }, []() {
- HTTPUpload& upload = server.upload();
- if (upload.status == UPLOAD_FILE_START) {
- Serial.setDebugOutput(true);
- WiFiUDP::stopAll();
- Serial.printf("Update: %s\n", upload.filename.c_str());
- uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
- if (!Update.begin(maxSketchSpace)) { //start with max available size
- Update.printError(Serial);
- }
- } else if (upload.status == UPLOAD_FILE_WRITE) {
- if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
- Update.printError(Serial);
- }
- } else if (upload.status == UPLOAD_FILE_END) {
- if (Update.end(true)) { //true to set the size to the current progress
- Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
- } else {
- Update.printError(Serial);
- }
- Serial.setDebugOutput(false);
- }
- yield();
- });
- server.begin();
- MDNS.addService("http", "tcp", 80);
- Serial.printf("Ready! Open http://%s.local in your browser\n", USER_MQTT_CLIENT_NAME);
- }
- void setup_wifi()
- {
- delay(10);
- // We start by connecting to a WiFi network
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.hostname(USER_MQTT_CLIENT_NAME);
- WiFi.begin(ssid, 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 reconnect()
- {
- // Loop until we're reconnected
- int retries = 0;
- while (!client.connected()) {
- if (retries < 150)
- {
- Serial.print("Attempting MQTT connection...");
- // Attempt to connect
- if (client.connect(mqtt_client_name, mqtt_user, mqtt_pass))
- {
- Serial.println("connected");
- // Once connected, publish an announcement...
- if (boot == true)
- {
- client.publish(USER_MQTT_CLIENT_NAME"/checkIn", "Rebooted");
- boot = false;
- }
- if (boot == false)
- {
- client.publish(USER_MQTT_CLIENT_NAME"/checkIn", "Reconnected");
- }
- // ... and resubscribe
- client.subscribe(USER_MQTT_CLIENT_NAME"/configure");
- client.subscribe(USER_MQTT_CLIENT_NAME"/modifier");
- client.subscribe(USER_MQTT_CLIENT_NAME"/effect");
- client.subscribe(USER_MQTT_CLIENT_NAME"/scene");
- client.subscribe(USER_MQTT_CLIENT_NAME"/state");
- client.subscribe(USER_MQTT_CLIENT_NAME"/color1");
- client.subscribe(USER_MQTT_CLIENT_NAME"/color2");
- client.subscribe(USER_MQTT_CLIENT_NAME"/color3");
- client.subscribe(USER_MQTT_CLIENT_NAME"/power");
- client.subscribe(USER_MQTT_CLIENT_NAME"/brightness");
- client.subscribe(USER_MQTT_CLIENT_NAME"/addEffects");
- client.subscribe(USER_MQTT_CLIENT_NAME"/lightningChance");
- client.subscribe(USER_MQTT_CLIENT_NAME"/glitterChance");
- client.subscribe(USER_MQTT_CLIENT_NAME"/glitterColor");
- }
- else
- {
- Serial.print("failed, rc=");
- Serial.print(client.state());
- Serial.println(" try again in 5 seconds");
- retries++;
- // Wait 5 seconds before retrying
- delay(5000);
- }
- }
- if (retries > 1500)
- {
- ESP.restart();
- }
- }
- }
- /************************** MQTT CALLBACK ***********************/
- void callback(char* topic, byte* payload, unsigned int length)
- {
- Serial.print("Message arrived [");
- String newTopic = topic;
- Serial.print(topic);
- Serial.print("] ");
- payload[length] = '\0';
- String newPayload = String((char *)payload);
- int intPayload = newPayload.toInt();
- Serial.println(newPayload);
- Serial.println();
- newPayload.toCharArray(charPayload, newPayload.length() + 1);
- if (newTopic == USER_MQTT_CLIENT_NAME"/modifier")
- {
- client.publish(USER_MQTT_CLIENT_NAME"/modifierState", charPayload);
- if (effect == "Double_Crash" || effect == "Single_Race")
- {
- raceSpeed = (intPayload / 20);
- }
- if (effect == "BPM")
- {
- BeatsPerMinute = (intPayload / 4);
- }
- if (effect == "Color_Chase" || effect == "Blocked_Colors")
- {
- chaseDelay = (intPayload * 5);
- if (chaseDelay < 100)
- {
- chaseDelay = 100;
- }
- }
- if (effect == "Color_Glitter")
- {
- glitterChance = (intPayload / 2);
- }
- if (effect == "Rainbow")
- {
- numberOfRainbows = (intPayload / 30);
- }
- if (effect == "Twinkle")
- {
- twinkleChance = map(intPayload, 0, 500, 0, 255);
- }
- if (effect == "Spooky_Eyes")
- {
- eyeChance = map(intPayload, 0, 500, 0, 255);
- }
- if (effect == "LED_Locator")
- {
- locatorDelay = map(intPayload, 0, 500, 500, 5000);
- }
- }
- if (newTopic == USER_MQTT_CLIENT_NAME"/addEffects")
- {
- if (newPayload == "Audio On")
- {
- audioEffects = true;
- client.publish(USER_MQTT_CLIENT_NAME"/audio/state", charPayload);
- }
- if (newPayload == "Audio Off")
- {
- audioEffects = false;
- client.publish(USER_MQTT_CLIENT_NAME"/audio/state", charPayload);
- }
- if (newPayload == "Glitter On")
- {
- showGlitter = true;
- client.publish(USER_MQTT_CLIENT_NAME"/glitter/state", charPayload);
- }
- if (newPayload == "Glitter Off")
- {
- showGlitter = false;
- client.publish(USER_MQTT_CLIENT_NAME"/glitter/state", charPayload);
- }
- if (newPayload == "Lightning On")
- {
- showLightning = true;
- client.publish(USER_MQTT_CLIENT_NAME"/lightning/state", "Lightning On");
- }
- if (newPayload == "Lightning Off")
- {
- showLightning = false;
- client.publish(USER_MQTT_CLIENT_NAME"/lightning/state", "Lightning Off");
- }
- }
- if (newTopic == USER_MQTT_CLIENT_NAME"/effect")
- {
- effect = newPayload;
- client.publish(USER_MQTT_CLIENT_NAME"/effectState", charPayload);
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- fill_solid(leds[led_i], numleds[led_i], CRGB::Black);
- if (effect == "LED_Locator")
- {
- locator_Move();
- }
- }
- if (newTopic == USER_MQTT_CLIENT_NAME"/scene")
- {
- scene = newPayload;
- client.publish(USER_MQTT_CLIENT_NAME"/sceneState", charPayload);
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- fill_solid(leds[led_i], numleds[led_i], CRGB::Black);
- }
- if (newTopic == USER_MQTT_CLIENT_NAME "/color1")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/color1State", charPayload);
- // get the position of the first and second commas
- uint8_t firstIndex = newPayload.indexOf(',');
- uint8_t lastIndex = newPayload.lastIndexOf(',');
- uint8_t rgb_red = newPayload.substring(0, firstIndex).toInt();
- if (rgb_red < 0 || rgb_red > 255) {
- return;
- } else {
- red1 = rgb_red;
- }
- uint8_t rgb_green = newPayload.substring(firstIndex + 1, lastIndex).toInt();
- if (rgb_green < 0 || rgb_green > 255) {
- return;
- } else {
- green1 = rgb_green;
- }
- uint8_t rgb_blue = newPayload.substring(lastIndex + 1).toInt();
- if (rgb_blue < 0 || rgb_blue > 255) {
- return;
- } else {
- blue1 = rgb_blue;
- }
- }
- if (newTopic == USER_MQTT_CLIENT_NAME "/color2")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/color2State", charPayload);
- // get the position of the first and second commas
- uint8_t firstIndex = newPayload.indexOf(',');
- uint8_t lastIndex = newPayload.lastIndexOf(',');
- uint8_t rgb_red = newPayload.substring(0, firstIndex).toInt();
- if (rgb_red < 0 || rgb_red > 255) {
- return;
- } else {
- red2 = rgb_red;
- }
- uint8_t rgb_green = newPayload.substring(firstIndex + 1, lastIndex).toInt();
- if (rgb_green < 0 || rgb_green > 255) {
- return;
- } else {
- green2 = rgb_green;
- }
- uint8_t rgb_blue = newPayload.substring(lastIndex + 1).toInt();
- if (rgb_blue < 0 || rgb_blue > 255) {
- return;
- } else {
- blue2 = rgb_blue;
- }
- }
- if (newTopic == USER_MQTT_CLIENT_NAME "/color3")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/color3State", charPayload);
- // get the position of the first and second commas
- uint8_t firstIndex = newPayload.indexOf(',');
- uint8_t lastIndex = newPayload.lastIndexOf(',');
- uint8_t rgb_red = newPayload.substring(0, firstIndex).toInt();
- if (rgb_red < 0 || rgb_red > 255) {
- return;
- } else {
- red3 = rgb_red;
- }
- uint8_t rgb_green = newPayload.substring(firstIndex + 1, lastIndex).toInt();
- if (rgb_green < 0 || rgb_green > 255) {
- return;
- } else {
- green3 = rgb_green;
- }
- uint8_t rgb_blue = newPayload.substring(lastIndex + 1).toInt();
- if (rgb_blue < 0 || rgb_blue > 255) {
- return;
- } else {
- blue3 = rgb_blue;
- }
- }
- if (newTopic == USER_MQTT_CLIENT_NAME "/glitterColor")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/glitterColorState", charPayload);
- // get the position of the first and second commas
- uint8_t firstIndex = newPayload.indexOf(',');
- uint8_t lastIndex = newPayload.lastIndexOf(',');
- uint8_t rgb_red = newPayload.substring(0, firstIndex).toInt();
- if (rgb_red < 0 || rgb_red > 255) {
- return;
- } else {
- redG = rgb_red;
- }
- uint8_t rgb_green = newPayload.substring(firstIndex + 1, lastIndex).toInt();
- if (rgb_green < 0 || rgb_green > 255) {
- return;
- } else {
- greenG = rgb_green;
- }
- uint8_t rgb_blue = newPayload.substring(lastIndex + 1).toInt();
- if (rgb_blue < 0 || rgb_blue > 255) {
- return;
- } else {
- blueG = rgb_blue;
- }
- }
- if (newTopic == USER_MQTT_CLIENT_NAME"/glitterChance")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/glitterChanceState", charPayload);
- glitterFrequency = intPayload;
- }
- if (newTopic == USER_MQTT_CLIENT_NAME"/lightningChance")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/lightningChanceState", charPayload);
- lightningChance = (65535 - intPayload);
- }
- if (newTopic == USER_MQTT_CLIENT_NAME"/brightness")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/brightnessState", charPayload);
- brightness = intPayload;
- }
- if (newTopic == USER_MQTT_CLIENT_NAME"/power")
- {
- client.publish(USER_MQTT_CLIENT_NAME "/powerState", charPayload);
- if (newPayload == "ON")
- {
- showLights = true;
- }
- if (newPayload == "OFF")
- {
- showLights = false;
- }
- }
- }
- /*********************** End WIFI MQTT *****************************/
- /***************** SYSTEM FUNCTIONS *************************************/
- // Don't think this is issue. WORRIED is startPosition globally conflicted if mult effects chosen
- void chase()
- {
- if (startPosition == 5)
- {
- startPosition = 0;
- }
- else
- {
- startPosition++;
- }
- timer.setTimeout(chaseDelay, chase);
- }
- void checkIn()
- {
- client.publish(USER_MQTT_CLIENT_NAME"/checkIn", "OK");
- timer.setTimeout(120000, checkIn);
- }
- int antipodal_index(int i, int NUM_LEDS) {
- int TOP_INDEX = int(NUM_LEDS / 2);
- int iN = i + TOP_INDEX;
- if (i >= TOP_INDEX) {
- iN = ( i + TOP_INDEX ) % NUM_LEDS;
- }
- return iN;
- }
- void choosePattern()
- {
- if (showLights == true)
- {
- if (effect != "Scene") {
- if (effect == "Color_Chase")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- ledRGB(led_i);
- }
- if (effect == "Color_Glitter")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- ColorGlitter(glitterChance, led_i);
- }
- if (effect == "Single_Race")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- SingleRace(led_i);
- }
- if (effect == "Double_Crash")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Crash(led_i);
- }
- if (effect == "Rainbow")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Rainbow(led_i);
- }
- if (effect == "Blocked_Colors")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Blocked(led_i);
- }
- if (effect == "BPM")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- BPM(led_i);
- }
- if (effect == "Twinkle")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Twinkle(led_i);
- }
- if (effect == "Fill_Solid")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Solid(led_i);
- }
- if (effect == "Spooky_Eyes")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Eyes(led_i, CRGB(red1, green1, blue1));
- }
- if (effect == "LED_Locator")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Locator(led_i);
- }
- if (effect == "Ripple")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Ripple(led_i);
- }
- if (effect == "Fire")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Fire(led_i);
- }
- if (effect == "Police")
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- Police(led_i);
- }
- // ****************** SCENES ************************
- /* Duke_Blocked
- A-Frame: Blocked
- Gutters: Solid
- */
- /* Duke Fire
- A-Frame: Fire
- Gutters: Solid
- */
- /* Halloween
- A-Frame: Fire
- Gutters: Eyes + Lightning
- */
- /* CandyCane
- A-Frame: Fire
- Gutters: Eyes
- */
- // Color_Chase - Dots Chasing each other
- // Color_Glitter – random Fill in Strips
- // Single_Race - Kind of tennis. Color streak/fade to one side, bounce back with another color
- // Double_Crash – Two Colors from middle and ends, bounce at ends and collide in middle
- // Rainbow – Size adjustable
- // Blocked_Colors – Banded and move in chunks not gradual
- // BPM – Seesaw back and forth (some sort of gradient involved as well within color
- } else {
- if (scene == "Halloween")
- {
- Fire(0, HeatColors_p);
- Fire(2, HeatColors_p);
- Eyes(1, CRGB(200, 20, 20));
- Eyes(3, CRGB(200, 20, 20));
- }
- if (scene == "Duke_Blocked")
- {
- fill_solid(leds[1], numleds[1], CRGB(0, 0, 151));
- fill_solid(leds[3], numleds[3], CRGB(0, 0, 151));
- Crawl(0, setupABStripedPalette(CRGB::Blue, CRGB::White));
- Crawl(2, setupABStripedPalette(CRGB::Blue, CRGB::White));
- }
- if (scene == "Duke_Fire") {
- // for (int led_i = 0;led_i<NUMZONES;led_i++)
- // Police(led_i,64,96);
- Fire(0, blue_gp );
- Fire(2, blue_gp );
- Blocked(1,CRGB::Blue,CRGB::White);
- Blocked(3,CRGB::Blue,CRGB::White);
- }
- }
- }
- // **************************** New Scenes/Prototypes **********************************
- if (scene == "Test") {
- // for (int led_i = 0;led_i<NUMZONES;led_i++)
- // Police(led_i,64,96);
- Crawl(0,setupABCDStripedPalette(CRGB(212,40,36), CRGB(220,120,12),CRGB(255,231,28), CRGB(88,115,36)));
- Crawl(1,setupABCDStripedPalette(CRGB(212,40,36), CRGB(220,120,12),CRGB(255,231,28), CRGB(88,115,36)));
- Crawl(2,setupABCDStripedPalette(CRGB(212,40,36), CRGB(220,120,12),CRGB(255,231,28), CRGB(88,115,36)));
- Crawl(3,setupABCDStripedPalette(CRGB(212,40,36), CRGB(220,120,12),CRGB(255,231,28), CRGB(88,115,36)));
- }
- // **************************** **********************************
- if (showLights == false)
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- fill_solid(leds[led_i], numleds[led_i], CRGB::Black);
- }
- if (showGlitter == true)
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- addGlitter(led_i);
- }
- if (showLightning == true)
- {
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- addLightning(led_i);
- }
- }
- void setup() {
- Serial.begin(115200);
- // calculateMax();
- FastLED.addLeds<CHIPSET, 5, COLOR_ORDER>(leds[0], numleds[0]);
- FastLED.addLeds<CHIPSET, 4, COLOR_ORDER>(leds[1], numleds[1]);
- FastLED.addLeds<CHIPSET, 14, COLOR_ORDER>(leds[2], numleds[2]);
- FastLED.addLeds<CHIPSET, 12, COLOR_ORDER>(leds[3], numleds[3]);
- FastLED.setDither( 0 );
- WiFi.setSleepMode(WIFI_NONE_SLEEP);
- WiFi.mode(WIFI_STA);
- setup_wifi();
- led_wifi();
- client.setServer(mqtt_server, mqtt_port);
- client.setCallback(callback);
- // ArduinoOTA.setHostname(USER_MQTT_CLIENT_NAME);
- // ArduinoOTA.begin();
- gPal = HeatColors_p;
- timer.setTimeout(10000, chase);
- timer.setTimeout(120000, checkIn);
- }
- void loop()
- {
- server.handleClient();
- if (!client.connected())
- {
- reconnect();
- }
- client.loop();
- if (showLights == false)
- {
- // ArduinoOTA.handle();
- server.handleClient();
- MDNS.update();
- }
- timer.run();
- EVERY_N_MILLISECONDS( 20 ) {
- gHue++;
- }
- choosePattern();
- for (int led_i = 0; led_i < NUMZONES; led_i++)
- FastLED[led_i].showLeds(brightness);
- }
- // Pattern Implementation Functions formerly ... _firstZone()...
- void locator_Move()
- {
- if (effect == "LED_Locator")
- {
- if (locatorLED <= maxLEDs)
- {
- String temp_str = String(locatorLED);
- temp_str.toCharArray(MQTT_locatorLED, temp_str.length() + 1);
- client.publish(USER_MQTT_CLIENT_NAME"/locator", MQTT_locatorLED);
- locatorLED++;
- }
- else
- {
- locatorLED = 0;
- }
- timer.setTimeout(locatorDelay, locator_Move);
- }
- }
- void addLightning(int led_i)
- {
- {
- fadeToBlackBy(leds[led_i], numleds[led_i], 1);
- unsigned int chance = random16();
- char chancestring[50];
- char chancestring2[50];
- itoa(chance, chancestring, 10);
- itoa(-1*lightningChance, chancestring2, 10);
- // chancestring = chancestring+"-"+chancestring2;
- if ( chance > lightningChance)
- {
- fill_solid(leds[led_i], numleds[led_i], CRGB::White);
- lightning[led_i] = 20;
- //
- client.publish("lightningtest",chancestring );
- client.publish("lightningtest",chancestring2 );
- if(audioEffects == true)
- {
- int thunder = random8();
- if( thunder > 128)
- {
- client.publish("Audio","1");
- }
- if( thunder < 127)
- {
- client.publish("Audio","1");
- }
- }
- //
- }
- if (lightning[led_i] != 1)
- {
- if (lightning[led_i] > 15)
- {
- fadeToBlackBy(leds[led_i], numleds[led_i], 150);
- lightning[led_i]--;
- }
- if (lightning[led_i] == 15)
- {
- fill_solid(leds[led_i], numleds[led_i], CRGB::White);
- lightning[led_i]--;
- }
- if (lightning[led_i] > 5 && lightning[led_i] < 15)
- {
- fadeToBlackBy(leds[led_i], numleds[led_i], 150);
- lightning[led_i]--;
- }
- if (lightning[led_i] == 5)
- {
- fill_solid(leds[led_i], numleds[led_i], CRGB::White);
- lightning[led_i]--;
- lightning[led_i]--;
- }
- if (lightning[led_i] > 0 && lightning[led_i] < 5)
- {
- fadeToBlackBy(leds[led_i], numleds[led_i], 150);
- lightning[led_i]--;
- }
- }
- }
- }
- void addGlitter(int led_i)
- {
- {
- if ( random8() < glitterFrequency)
- {
- leds[led_i][ random16(numleds[led_i]) ] = CRGB(redG, greenG, blueG);
- }
- }
- }
- void ledRGB( int led_i)
- {
- if (startPosition < 6)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 80);
- for (int pixel = startPosition + 1; pixel < numleds[led_i]; pixel += 6)
- {
- if (pixel <= numleds[led_i])
- {
- leds[led_i][pixel] = CRGB(red1, green1, blue1);
- }
- }
- for (int pixel = startPosition + 3; pixel < numleds[led_i]; pixel += 6)
- {
- if (pixel <= numleds[led_i])
- {
- leds[led_i][pixel] = CRGB(red2, green2, blue2);
- }
- }
- for (int pixel = startPosition + 5; pixel < numleds[led_i]; pixel += 6)
- {
- if (pixel <= numleds[led_i])
- {
- leds[led_i][pixel] = CRGB(red3, green3, blue3);
- }
- }
- }
- if (startPosition == 1)
- {
- leds[led_i][0] = CRGB(red3, green3, blue3);
- }
- if (startPosition == 2)
- {
- leds[led_i][1] = CRGB(red3, green3, blue3);
- }
- if (startPosition == 3)
- {
- leds[led_i][2] = CRGB(red3, green3, blue3);
- leds[led_i][0] = CRGB(red2, green2, blue2);
- }
- if (startPosition == 4)
- {
- leds[led_i][3] = CRGB(red3, green3, blue3);
- leds[led_i][1] = CRGB(red2, green2, blue2);
- }
- if (startPosition == 5)
- {
- leds[led_i][4] = CRGB(red3, green3, blue3);
- leds[led_i][2] = CRGB(red2, green2, blue2);
- leds[led_i][0] = CRGB(red1, green1, blue1);
- }
- }
- // ********************************** Blocked Overloaded ***************************************************
- void Blocked(int led_i)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 2);
- for ( int mark = 0; mark < numleds[led_i]; mark += 30)
- {
- for ( int i = 0; i < 9; i++)
- {
- if (startPosition == 0 || startPosition == 1)
- {
- if (i + mark <= numleds[led_i])
- {
- leds[led_i][i + mark] = CRGB(red1, green1, blue1);
- }
- if (i + 10 + mark <= numleds[led_i])
- {
- leds[led_i][i + 10 + mark] = CRGB(red2, green2, blue2);
- }
- if (i + 20 + mark <= numleds[led_i])
- {
- leds[led_i][i + 20 + mark] = CRGB(red3, green3, blue3);
- }
- }
- if (startPosition == 2 || startPosition == 3)
- {
- if (i + mark <= numleds[led_i])
- {
- leds[led_i][i + mark] = CRGB(red2, green2, blue2);
- }
- if (i + 10 + mark <= numleds[led_i])
- {
- leds[led_i][i + 10 + mark] = CRGB(red3, green3, blue3);
- }
- if (i + 20 + mark <= numleds[led_i])
- {
- leds[led_i][i + 20 + mark] = CRGB(red1, green1, blue1);
- }
- }
- if (startPosition == 4 || startPosition == 5)
- {
- if (i + mark <= numleds[led_i])
- {
- leds[led_i][i + mark] = CRGB(red3, green3, blue3);
- }
- if (i + 10 + mark <= numleds[led_i])
- {
- leds[led_i][i + 10 + mark] = CRGB(red1, green1, blue1);
- }
- if (i + 20 + mark <= numleds[led_i])
- {
- leds[led_i][i + 20 + mark] = CRGB(red2, green2, blue2);
- }
- }
- }
- }
- }
- void Blocked(int led_i, CRGB color1, CRGB color2)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 2);
- for ( int mark = 0; mark < numleds[led_i]; mark += 20)
- {
- for ( int i = 0; i < 9; i++)
- {
- if (startPosition == 0 || startPosition == 1 || startPosition == 2)
- {
- if (i + mark <= numleds[led_i])
- {
- leds[led_i][i + mark] = color1;
- }
- if (i + 10 + mark <= numleds[led_i])
- {
- leds[led_i][i + 10 + mark] = color2;
- }
- }
- if (startPosition == 3 || startPosition == 4 || startPosition == 5)
- {
- if (i + mark <= numleds[led_i])
- {
- leds[led_i][i + mark] = color2;
- }
- if (i + 10 + mark <= numleds[led_i])
- {
- leds[led_i][i + 10 + mark] = color1;
- }
- }
- }
- }
- }
- // ********************************** Blocked Overloaded End ***************************************************
- void Rainbow(int led_i)
- {
- fill_rainbow( leds[led_i], numleds[led_i], gHue, numberOfRainbows);
- }
- // ********************************** Crash Overloaded ***************************************************
- void Crash(int led_i)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 15);
- for (int led_j = 1; led_j <= sections[led_i][0]; led_j++) {
- int pos_SECTION = beatsin16( raceSpeed, 0, (sections[led_i][led_j + 1] - 1 - sections[led_i][led_j]) );
- leds[led_i][sections[led_i][led_j] + pos_SECTION] = CRGB(red1, green1, blue1);
- leds[led_i][sections[led_i][led_j + 1] - 1 - pos_SECTION] = CRGB(red2, green2, blue2);
- }
- }
- void Crash(int led_i, CRGB color1, CRGB color2)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 15);
- for (int led_j = 1; led_j <= sections[led_i][0]; led_j++) {
- int pos_SECTION = beatsin16( raceSpeed, 0, (sections[led_i][led_j + 1] - 1 - sections[led_i][led_j]) );
- leds[led_i][sections[led_i][led_j] + pos_SECTION] = color1;
- leds[led_i][sections[led_i][led_j + 1] - 1 - pos_SECTION] = color2;
- }
- }
- // ********************************** Crash Overloaded ended ***************************************************
- void Eyes(int led_i, CRGB color)
- {
- unsigned int chance = random8();
- if ( chance > eyeChance)
- {
- unsigned int eye = random16(numleds[led_i]);
- leds[led_i][eye] = color;
- leds[led_i][eye - 4] = color;
- }
- if ( chance > 39)
- {
- fadeToBlackBy( leds[ led_i], numleds[led_i], 10);
- }
- }
- // ********************************** Fire Overloaded ***************************************************
- void Fire(int led_i)
- {
- for (int led_j = 1; led_j <= sections[led_i][0]; led_j++) {
- // int sections[NUMZONES][MAXSECTIONS+2] = { {2,0,137,272}, {1,0,286,286},{2,0,134,266},{1,0,209,209} };
- // int firestarters[NUMZONES][2*MAXSECTIONS]= { {1,0,0,1,0,0}, {1,1,0,0,0,0},{1,0,0,1,0,0},{1,1,0,0,0,0} };
- int numfireleds = sections[led_i][led_j + 1] - sections[led_i][led_j];
- static byte heat[NUMZONES][MAXNUMLEDS];
- for ( int i = sections[led_i][led_j]; i < sections[led_i][led_j + 1]; i++)
- {
- heat[led_i][i] = qsub8( heat[led_i][i], random8(0, ((COOLING * 10) / numfireleds) + 2));
- }
- for ( int k = sections[led_i][led_j + 1] - 1; k >= sections[led_i][led_j] + 2; k--)
- {
- heat[led_i][k] = (heat[led_i][k - 1] + heat[led_i][k - 2] + heat[led_i][k - 2] ) / 3;
- }
- if ( random8() < SPARKING )
- {
- int y = random8(7);
- heat[led_i][sections[led_i][led_j] + y] = qadd8( heat[led_i][sections[led_i][led_j] + y], random8(160, 255) );
- }
- for ( int j = 0; j < numfireleds; j++)
- {
- byte colorindex = scale8( heat[led_i][sections[led_i][led_j] + j], 240);
- CRGB color = ColorFromPalette( gPal, colorindex);
- int pixelnumber;
- if ( gReverseDirection ) {
- pixelnumber = (numfireleds - 1) - j;
- } else {
- pixelnumber = j;
- }
- int thisFlame = ((pixelnumber * firesize[led_i]) / 100);
- // if(thisFlame <= numfireleds )
- if (firestarters[led_i][2 * led_j - 2] == 1)
- {
- leds[led_i][sections[led_i][led_j] + thisFlame] = color;
- }
- if (firestarters[led_i][2 * led_j - 1] == 1)
- {
- leds[led_i][sections[led_i][led_j + 1] - 1 - thisFlame] = color;
- }
- }
- }
- }
- void Fire(int led_i, CRGBPalette16 flames)
- {
- for (int led_j = 1; led_j <= sections[led_i][0]; led_j++) {
- // int sections[NUMZONES][MAXSECTIONS+2] = { {2,0,137,272}, {1,0,286,286},{2,0,134,266},{1,0,209,209} };
- // int firestarters[NUMZONES][2*MAXSECTIONS]= { {1,0,0,1,0,0}, {1,1,0,0,0,0},{1,0,0,1,0,0},{1,1,0,0,0,0} };
- int numfireleds = sections[led_i][led_j + 1] - sections[led_i][led_j];
- static byte heat[NUMZONES][MAXNUMLEDS];
- for ( int i = sections[led_i][led_j]; i < sections[led_i][led_j + 1]; i++)
- {
- heat[led_i][i] = qsub8( heat[led_i][i], random8(0, ((COOLING * 10) / numfireleds) + 2));
- }
- for ( int k = sections[led_i][led_j + 1] - 1; k >= sections[led_i][led_j] + 2; k--)
- {
- heat[led_i][k] = (heat[led_i][k - 1] + heat[led_i][k - 2] + heat[led_i][k - 2] ) / 3;
- }
- if ( random8() < SPARKING )
- {
- int y = random8(7);
- heat[led_i][sections[led_i][led_j] + y] = qadd8( heat[led_i][sections[led_i][led_j] + y], random8(160, 255) );
- }
- for ( int j = 0; j < numfireleds; j++)
- {
- byte colorindex = scale8( heat[led_i][sections[led_i][led_j] + j], 240);
- CRGB color = ColorFromPalette( flames, colorindex);
- int pixelnumber;
- if ( gReverseDirection ) {
- pixelnumber = (numfireleds - 1) - j;
- } else {
- pixelnumber = j;
- }
- int thisFlame = ((pixelnumber * firesize[led_i]) / 100);
- // if(thisFlame <= numfireleds )
- if (firestarters[led_i][2 * led_j - 2] == 1)
- {
- leds[led_i][sections[led_i][led_j] + thisFlame] = color;
- }
- if (firestarters[led_i][2 * led_j - 1] == 1)
- {
- leds[led_i][sections[led_i][led_j + 1] - 1 - thisFlame] = color;
- }
- }
- }
- }
- // ********************************** Fire Overloaded ended ***************************************************
- void ColorGlitter( fract8 chanceOfGlitter, int led_i)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 2);
- if (startPosition == 0)
- {
- if ( random8() < chanceOfGlitter)
- {
- leds[led_i][ random16(numleds[led_i]) ] += CRGB::Red;
- }
- }
- if (startPosition == 1)
- {
- if ( random8() < chanceOfGlitter)
- {
- leds[led_i][ random16(numleds[led_i]) ] += CRGB::Orange;
- }
- }
- if (startPosition == 2)
- {
- if ( random8() < chanceOfGlitter)
- {
- leds[led_i][ random16(numleds[led_i]) ] += CRGB::Yellow;
- }
- }
- if (startPosition == 3)
- {
- if ( random8() < chanceOfGlitter)
- {
- leds[led_i][ random16(numleds[led_i]) ] += CRGB::Green;
- }
- }
- if (startPosition == 4)
- {
- if ( random8() < chanceOfGlitter)
- {
- leds[led_i][ random16(numleds[led_i]) ] += CRGB::Blue;
- }
- }
- if (startPosition == 5)
- {
- if ( random8() < chanceOfGlitter)
- {
- leds[led_i][ random16(numleds[led_i]) ] += CRGB::Violet;
- }
- }
- }
- // ********** BPM Overloaded ********************************************
- void BPM(int led_i)
- {
- if ((red1 * 2) > (green1 + blue1))
- {
- CRGBPalette16 palette_Zone = LavaColors_p;
- uint8_t beat = beatsin16( BeatsPerMinute, 64, 255);
- for ( int i = 0; i < numleds[led_i]; i++)
- {
- leds[led_i][i] = ColorFromPalette(palette_Zone, gHue + (i * 2), beat - gHue + (i * 10));
- }
- }
- if ((green1 * 2) > (red1 + blue1))
- {
- CRGBPalette16 palette_Zone = ForestColors_p;
- uint8_t beat = beatsin16( BeatsPerMinute, 64, 255);
- for ( int i = 0; i < numleds[led_i]; i++)
- {
- leds[led_i][i] = ColorFromPalette(palette_Zone, gHue + (i * 2), beat - gHue + (i * 10));
- }
- }
- if ((blue1 * 2) > (green1 + red1))
- {
- CRGBPalette16 palette_Zone = CloudColors_p;
- uint8_t beat = beatsin16( BeatsPerMinute, 64, 255);
- for ( int i = 0; i < numleds[led_i]; i++)
- {
- leds[led_i][i] = ColorFromPalette(palette_Zone, gHue + (i * 2), beat - gHue + (i * 10));
- }
- }
- if ((blue1 * 2) == (green1 + red1))
- {
- CRGBPalette16 palette_Zone = PartyColors_p;
- uint8_t beat = beatsin16( BeatsPerMinute, 64, 255);
- for ( int i = 0; i < numleds[led_i]; i++)
- {
- leds[led_i][i] = ColorFromPalette(palette_Zone, gHue + (i * 2), beat - gHue + (i * 10));
- }
- }
- }
- void BPM (int led_i, CRGBPalette16 palette)
- {
- uint8_t BeatsPerMinute = 62;
- uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- for ( int i = 0; i < numleds[led_i]; i++) { //9948
- leds[led_i][i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
- }
- }
- // ********** BPM Overloaded End ********************************************
- void Twinkle(int led_i)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 80);
- for ( int i = 0; i < numleds[led_i] - 5; i += 5)
- {
- if (i <= numleds[led_i])
- {
- if (random8() > twinkleChance)
- {
- leds[led_i][i] = CRGB( red1, green1, blue1);
- }
- else
- {
- leds[led_i][i] = CRGB( 150, 100, 40);
- }
- }
- }
- }
- // ********** Solid Overloaded ********************************************
- void Solid(int led_i)
- {
- fill_solid(leds[led_i], numleds[led_i], CRGB(red1, green1, blue1));
- }
- void Solid(int led_i, CRGB color)
- {
- fill_solid(leds[led_i], numleds[led_i], color);
- }
- // ********** Solid Overloaded ********************************************
- void Locator(int led_i)
- {
- if (locatorLED <= numleds[led_i])
- {
- fill_solid(leds[led_i], numleds[led_i], CRGB::Black);
- leds[led_i][locatorLED] = CRGB(red1, green1, blue1);
- }
- }
- // ********** SingleRace Overloaded ********************************************
- void SingleRace(int led_i)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 1);
- int pos = beatsin16( raceSpeed, 0, numleds[led_i]);
- if (pos > previousLED[led_i])
- {
- leds[led_i][pos] = CRGB(red1, green1, blue1);
- previousLED[led_i] = pos;
- }
- if (pos < previousLED[led_i])
- {
- leds[led_i][pos] = CRGB(red2, green2, blue2);
- previousLED[led_i] = pos;
- }
- }
- void SingleRace(int led_i, CRGB color1, CRGB color2)
- {
- fadeToBlackBy( leds[led_i], numleds[led_i], 1);
- int pos = beatsin16( raceSpeed, 0, numleds[led_i]);
- if (pos > previousLED[led_i])
- {
- leds[led_i][pos] = color1;
- previousLED[led_i] = pos;
- }
- if (pos < previousLED[led_i])
- {
- leds[led_i][pos] = color2;
- previousLED[led_i] = pos;
- }
- }
- // ********** SingleRace Overloaded Ended ********************************************
- // ********** Ripple Overloaded Ended ********************************************
- void Ripple(int led_i)
- {
- for (int i = 0; i < numleds[led_i]; i++)
- {
- leds[led_i][i] = CRGB((red2 / 75), (green2 / 75), (blue2 / 75));
- }
- switch (step[led_i])
- {
- case -1:
- center[led_i] = random16(numleds[led_i]);
- step[led_i] = 0;
- break;
- case 0:
- leds[led_i][center[led_i]] = CRGB(red1, green1, blue1);
- step[led_i] ++;
- break;
- case 12:
- step[led_i] = -1;
- break;
- default: // Middle of the ripples.
- leds[led_i][(center[led_i] + step[led_i] + numleds[led_i]) % numleds[led_i]] += CRGB((red1 / (step[led_i] * 5)), (green1 / (step[led_i] * 5)), (blue1 / (step[led_i] * 5)));
- leds[led_i][(center[led_i] - step[led_i] + numleds[led_i]) % numleds[led_i]] += CRGB((red1 / (step[led_i] * 5)), (green1 / (step[led_i] * 5)), (blue1 / (step[led_i] * 5)));
- step[led_i] ++;
- break;
- }
- }
- void Ripple(int led_i, CRGB color1, CRGB color2)
- {
- for (int i = 0; i < numleds[led_i]; i++)
- {
- leds[led_i][i] = CRGB((color2.red / 75), (color2.green / 75), (color2.blue / 75));
- }
- switch (step[led_i])
- {
- case -1:
- center[led_i] = random16(numleds[led_i]);
- step[led_i] = 0;
- break;
- case 0:
- leds[led_i][center[led_i]] = CRGB(red1, green1, blue1);
- step[led_i] ++;
- break;
- case 12:
- step[led_i] = -1;
- break;
- default: // Middle of the ripples.
- leds[led_i][(center[led_i] + step[led_i] + numleds[led_i]) % numleds[led_i]] += CRGB((color1.red / (step[led_i] * 5)), (color1.green / (step[led_i] * 5)), (color1.blue / (step[led_i] * 5)));
- leds[led_i][(center[led_i] - step[led_i] + numleds[led_i]) % numleds[led_i]] += CRGB((color1.red / (step[led_i] * 5)), (color1.green / (step[led_i] * 5)), (color1.blue / (step[led_i] * 5)));
- step[led_i] ++;
- break;
- }
- }
- // ********** Ripple Overloaded Ended ********************************************
- // *************** New Functions ***********************
- void Crawl (int led_i, CRGBPalette16 colorPalette)
- {
- static uint8_t startIndex[NUMZONES] = {0};
- startIndex[led_i] = startIndex[led_i] + 1; /* higher = faster motion */
- fill_palette( leds[led_i], numleds[led_i],
- startIndex[led_i], 16, /* higher = narrower stripes */
- colorPalette, 255, LINEARBLEND);
- }
- // ********** Police Overloaded ********************************************
- void Police(int led_i)
- { //POLICE LIGHTS (TWO COLOR SOLID)
- idex[led_i]++;
- if (idex[led_i] >= numleds[led_i]) {
- idex[led_i] = 0;
- }
- int idexR = idex[led_i];
- int idexB = antipodal_index(idexR, numleds[led_i]);
- // int thathue = (thishue + delhue) % 255;
- leds[led_i][idexR] = CRGB(red1, green1, blue1); //CHSV(thishue, 255, 255);
- leds[led_i][idexB] = CRGB(red2, green2, blue2); //CHSV(thathue, 255, 255);
- }
- void Police(int led_i, CRGB color1, CRGB color2)
- { //POLICE LIGHTS (TWO COLOR SOLID)
- idex[led_i]++;
- if (idex[led_i] >= numleds[led_i]) {
- idex[led_i] = 0;
- }
- int idexR = idex[led_i];
- int idexB = antipodal_index(idexR, numleds[led_i]);
- // int thathue = (thishue + delhue) % 255;
- leds[led_i][idexR] = color1; //CHSV(thishue, 255, 255);
- leds[led_i][idexB] = color2; //CHSV(thathue, 255, 255);
- }
- // ********** Police Overloaded Ended ********************************************
- // Twinkle
- // Fire
- // Fill_Solid
- // Spooky_Eyes
- // LED_Locator
Advertisement
Add Comment
Please, Sign In to add comment