#include #include #include #ifdef __AVR__ #include // Required for 16 MHz Adafruit Trinket #endif #define PIN D4 // change to the pin number where you connect the strip #define NUMPIXELS 15 // how many LED's are there on the strip ESP8266WebServer server; char* ssid = "SSID"; //put in YOUR wifi network name char* password = "PASS"; //put in YOUR wifi password, leave blank for open networks Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //makes an led strip object bool stripON; //variable which stores the strip state, true when strip is on, false when it is off int whatToDo; //variable for switching modes unsigned long previousMillis = 0; unsigned long previousMillis2 = 0; unsigned long currentMillis; unsigned long currentMillis2; //debounce variables const int ledPin = LED_BUILTIN; // the number of the LED pin int ledState = LOW; // ledState used to set the LED unsigned long previousMillis3 = 0; // will store last time LED was updated const long interval = 1000; // interval at which to blink (milliseconds) int R; int G; int B; //the 8bit RGB values for the color of the strip uint32_t fire_color = pixels.Color ( 80, 35, 00); uint32_t off_color = pixels.Color ( 0, 0, 0); //colors for the fire mode //char array in which the entire webpage we are sending is stored // formated in string literal char webpage[] PROGMEM = R"=====( RGB lamp
colormap #003366#336699#3366CC#003399#000099#0000CC#000066#006666#006699#0099CC#0066CC#0033CC#0000FF#3333FF#333399#669999#009999#33CCCC#00CCFF#0099FF#0066FF#3366FF#3333CC#666699#339966#00CC99#00FFCC#00FFFF#33CCFF#3399FF#6699FF#6666FF#6600FF#6600CC#339933#00CC66#00FF99#66FFCC#66FFFF#66CCFF#99CCFF#9999FF#9966FF#9933FF#9900FF#006600#00CC00#00FF00#66FF99#99FFCC#CCFFFF#CCCCFF#CC99FF#CC66FF#CC33FF#CC00FF#9900CC#003300#009933#33CC33#66FF66#99FF99#CCFFCC#FFFFFF#FFCCFF#FF99FF#FF66FF#FF00FF#CC00CC#660066#336600#009900#66FF33#99FF66#CCFF99#FFFFCC#FFCCCC#FF99CC#FF66CC#FF33CC#CC0099#993399#333300#669900#99FF33#CCFF66#FFFF99#FFCC99#FF9999#FF6699#FF3399#CC3399#990099#666633#99CC00#CCFF33#FFFF66#FFCC66#FF9966#FF6666#FF0066#CC6699#993366#999966#CCCC00#FFFF00#FFCC00#FF9933#FF6600#FF5050#CC0066#660033#996633#CC9900#FF9900#CC6600#FF3300#FF0000#CC0000#990033#663300#996600#CC3300#993300#990000#800000#993333
 
)====="; //////////////////////////////////////////end of HTML webpage class NeoFire{ //class for the fire effect Adafruit_NeoPixel &pixels; public: NeoFire(Adafruit_NeoPixel&); void Draw(); void Clear(); void AddColor(uint8_t position, uint32_t color); void SubstractColor(uint8_t position, uint32_t color); uint32_t Blend(uint32_t color1, uint32_t color2); uint32_t Substract(uint32_t color1, uint32_t color2); }; NeoFire::NeoFire(Adafruit_NeoPixel& n_strip) : pixels (n_strip) { } uint32_t Wheel(byte WheelPos) { //wheel function, gets the position of each LED on the strip based on it's order if (WheelPos < 85) { return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } else if (WheelPos < 170) { WheelPos -= 85; return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else { WheelPos -= 170; return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3); } } void NeoFire::Draw() { Clear(); for(int i=0;i> 16), g1 = (uint8_t)(color1 >> 8), b1 = (uint8_t)(color1 >> 0); r2 = (uint8_t)(color2 >> 16), g2 = (uint8_t)(color2 >> 8), b2 = (uint8_t)(color2 >> 0); return pixels.Color(constrain(r1+r2, 0, 255), constrain(g1+g2, 0, 255), constrain(b1+b2, 0, 255)); } uint32_t NeoFire::Substract(uint32_t color1, uint32_t color2) { uint8_t r1,g1,b1; uint8_t r2,g2,b2; uint8_t r3,g3,b3; int16_t r,g,b; r1 = (uint8_t)(color1 >> 16), g1 = (uint8_t)(color1 >> 8), b1 = (uint8_t)(color1 >> 0); r2 = (uint8_t)(color2 >> 16), g2 = (uint8_t)(color2 >> 8), b2 = (uint8_t)(color2 >> 0); r=(int16_t)r1-(int16_t)r2; g=(int16_t)g1-(int16_t)g2; b=(int16_t)b1-(int16_t)b2; if(r<0) r=0; if(g<0) g=0; if(b<0) b=0; return pixels.Color(r, g, b); } void NeoFire::Clear() { for(uint16_t i=0; i> 16; G = number >> 8 & 0xFF; B = number & 0xFF; //conversion from hex color format to RGB color format // values are stored in R, G and B variables for(int i=0; i= 800) { previousMillis = currentMillis; for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel for (i = 0; i < pixels.numPixels(); i++) { pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255)); } pixels.show(); } } break; case 7: if (currentMillis2 - previousMillis2 >= random(50,150)) { previousMillis2 = currentMillis2; fire.Draw(); } break; } unsigned long currentMillis3 = millis(); if (currentMillis3 - previousMillis3 >= interval) { // save the last time you blinked the LED previousMillis3 = currentMillis3; // if the LED is off turn it on and vice-versa: if (ledState == LOW) { ledState = HIGH; } else { ledState = LOW; } digitalWrite(ledPin, ledState); //blinks the esp's built in led } }