Advertisement
GyroGearloose

ESP_Webserver_Acces_point_does_not_work

Feb 21st, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.83 KB | None | 0 0
  1.  /*-----------------------------------------------------------------------------------------------------
  2.    Access Point                        Web Server  e.g.
  3.    http://192.168.4.1                  http://192.168.1.252 (depends on your network)
  4.    DOES NOT WORK    
  5.  
  6.  
  7. // FastLED setup ----------   FastLED has to be declared BEFORE the Webserver     ---------------------
  8. #include "FastLED.h"
  9. FASTLED_USING_NAMESPACE
  10.  
  11. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  12. #warning "Requires FastLED 3.1 or later; check github for latest code."
  13. #endif
  14.  
  15. #define DATA_PIN      13     // for Huzzah: Pins w/o special function:  #4, #5, #12, #13, #14; // #16 does not work :(
  16. //#define CLK_PIN     12
  17. //#define LED_TYPE    APA102
  18. //#define COLOR_ORDER BGR
  19. #define LED_TYPE      WS2811
  20. #define COLOR_ORDER   GRB
  21. #define NUM_LEDS      133    
  22. CRGB leds[NUM_LEDS];
  23.  
  24. //#define BRIGHTNESS       128
  25. int BRIGHTNESS =           128;   // this is half brightness
  26. int new_BRIGHTNESS =       128;   // shall be initially the same as brightness
  27.  
  28. #define MILLI_AMPERE      2000    // IMPORTANT: set here the max milli-Amps of your power supply 5V 2A = 2000
  29. #define FRAMES_PER_SECOND  120    // here you can control the speed. With the Access Point / Web Server the
  30.                                   // animations run a bit slower.
  31.  
  32. int ledMode = 2;                  // this is the starting animation
  33.  
  34. // WiFi setup -----------------------------------------------------
  35. // Comment out to use AccessPoint STA/station mode
  36. #define USE_AP             // Comment out to use WebServer mode
  37.  
  38. #include <ESP8266WiFi.h>
  39. // comes with Huzzah installation. Enter in Arduino settings:
  40. // http://arduino.esp8266.com/package_esp8266com_index.json
  41.  
  42.  
  43. // as WebServer
  44. const char* WebServer_ssid     = "your WLAN Name here";  
  45. const char* WebServer_password = "Your password here";
  46.  
  47. // as AccessPoint
  48. const char* AP_ssid     = "ESP_FastLED_Access_Point";
  49. const char* AP_password = "";  // set to "" for open access point w/o password; or any other pw (min length = 8 characters)
  50.  
  51. unsigned long ulReqcount;
  52. unsigned long ulReconncount;
  53.  
  54. WiFiServer server(80);  // Create an instance of the server on Port 80      
  55. //IPAddress apIP(192, 168, 10, 1);                             // if you want to configure another AccessPoint IP address
  56.                                                                // DO NOT USE 192.168.1.1 (That's might be your router !)
  57. void setup()
  58. {
  59.   // setup globals
  60.   ulReqcount=0;
  61.   ulReconncount=0;
  62.  
  63.   // prepare GPIO2
  64.   pinMode(2, OUTPUT);
  65.   digitalWrite(2, 0);
  66.  
  67.   // start serial
  68.   Serial.begin(9600);
  69.   delay(1);
  70.  
  71. #ifdef USE_AP
  72.   // AccesPoint mode
  73.   WiFi.mode(WIFI_AP);
  74. //  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));          // if you want to configure another IP address
  75.   WiFi.softAP(AP_ssid, AP_password);
  76.   Serial.println("AccessPoint is set to 192.168.4.1");
  77.  
  78. #else
  79.   // WebServer mode
  80.   Serial.println("Starting Webserver");
  81.   WiFi.mode(WIFI_STA);
  82.   WiFiStart();
  83.  
  84. #endif
  85.  
  86. // ... and finally the settings for FastLED    
  87.   delay(1000); // sanity delay for LEDs
  88.   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(DirectSunlight);
  89.   //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(DirectSunlight);
  90.   FastLED.setBrightness(BRIGHTNESS);
  91.   set_max_power_in_volts_and_milliamps(5, MILLI_AMPERE);
  92. }
  93.  
  94.  
  95.  
  96. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  97.  
  98. void WiFiStart()
  99. {
  100.  
  101.   // Connect to WiFi network
  102.   Serial.println();
  103.   Serial.println();
  104.   Serial.print("Connecting to ");
  105.   Serial.println(WebServer_ssid);
  106.  
  107.   WiFi.begin(WebServer_ssid, WebServer_password);
  108.  
  109.   while (WiFi.status() != WL_CONNECTED) {
  110.     delay(500);
  111.     Serial.print(".");
  112.   }
  113.   Serial.println("");
  114.   Serial.println("WiFi connected");
  115.  
  116.   // Start the server
  117.   server.begin();
  118.   Serial.println("Server started");
  119.  
  120.   // Print the IP address
  121.   Serial.println(WiFi.localIP());
  122. }
  123.  
  124. void loop() {
  125.   webserver();
  126.  
  127.   if (ledMode != 999) {
  128.  
  129.      switch (ledMode) {
  130.       case  1: all_off(); break;
  131.       case  2: rainbow(); break;
  132.       case  3: rainbowWithGlitter(); break;
  133.       case  4: confetti(); break;
  134.       case  5: sinelon(); break;
  135.       case  6: juggle(); break;
  136.       case  7: bpm(); break;
  137.       }
  138.       }
  139.   show_at_max_brightness_for_power();
  140.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  141. //  FastLED.show();  
  142. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  143.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  144.  
  145. } // end of loop ************************************************************************************************************
  146.  
  147.  
  148. void webserver() {   /// complete web server (same for access point) ////////////////////////////////////////////////////////
  149.   // Check if a client has connected
  150.   WiFiClient client = server.available();
  151.   if (!client)
  152.   {
  153.     return;
  154.   }
  155.  
  156.   // Wait until the client sends some data
  157.   Serial.println("new client");
  158.   unsigned long ultimeout = millis()+250;
  159.   while(!client.available() && (millis()<ultimeout) )
  160.   {
  161.     delay(1);
  162.   }
  163.   if(millis()>ultimeout)
  164.   {
  165.     Serial.println("client connection time-out!");
  166.     return;
  167.   }
  168.  
  169.   // Read the first line of the request
  170.  
  171.   String sRequest = client.readStringUntil('\r');
  172.   Serial.println(sRequest);
  173.   client.flush();
  174.  
  175.   // stop client, if request is empty
  176.   if(sRequest=="")
  177.   {
  178.     Serial.println("empty request! - stopping client");
  179.     client.stop();
  180.     return;
  181.   }
  182.  
  183.   // get path; end of path is either space or ?
  184.   // Syntax is e.g. GET /?pin=MOTOR1STOP HTTP/1.1
  185.   String sPath="",sParam="", sCmd="";
  186.   String sGetstart="GET ";
  187.   int iStart,iEndSpace,iEndQuest;
  188.   iStart = sRequest.indexOf(sGetstart);
  189. //  Serial.print("iStart ");
  190. //  Serial.println(iStart);
  191.  
  192.   if (iStart>=0)
  193.   {
  194.     iStart+=+sGetstart.length();
  195. //  Serial.print("iStart + sGetstart ");
  196. //  Serial.println(iStart);
  197.     iEndSpace = sRequest.indexOf(" ",iStart);
  198. //  Serial.print("iEndSpace ");
  199. //  Serial.println(iEndSpace);
  200.     iEndQuest = sRequest.indexOf("?",iStart);
  201. //  Serial.print("iEndQuest ");
  202. //  Serial.println(iEndQuest);    
  203.     // are there parameters?
  204.     if(iEndSpace>0)
  205.     {
  206.       if(iEndQuest>0)
  207.       {
  208.         // there are parameters
  209.         sPath  = sRequest.substring(iStart,iEndQuest);
  210.         sParam = sRequest.substring(iEndQuest,iEndSpace);
  211.       }
  212.       else
  213.       {
  214.         // NO parameters
  215.         sPath  = sRequest.substring(iStart,iEndSpace);
  216.       }
  217.     }
  218.   }
  219.  
  220.   //////////////////////////////////////////////////////////////////////////////////
  221.   // output parameters to serial, you may connect e.g. an Arduino and react on it //
  222.   //////////////////////////////////////////////////////////////////////////////////
  223.   if(sParam.length()>0)
  224.   {
  225.     int iEqu=sParam.indexOf("=");
  226.     if(iEqu>=0)
  227.     {
  228.       sCmd = sParam.substring(iEqu+1,sParam.length());
  229.       Serial.print("We are in output Parameters, value is: ");
  230.       Serial.println(sCmd);
  231.       char carray[4];                                // values 0..255 = 3 digits; array = digits + 1
  232.       sCmd.toCharArray(carray, sizeof(carray));      // convert char to the array
  233.       new_BRIGHTNESS = atoi(carray);                 // atoi() converts an ascii character array to an integer
  234.       if (new_BRIGHTNESS == 0) {new_BRIGHTNESS = BRIGHTNESS; }   // if something else is selected (no change in brightness)
  235.          BRIGHTNESS = new_BRIGHTNESS;                // assign new value for the HTML page
  236.          FastLED.setBrightness(new_BRIGHTNESS);      // that's how the new value is assigned  
  237.       Serial.print("new Brightness: ");
  238.       Serial.println(new_BRIGHTNESS);
  239.     }
  240.   }
  241.  
  242.   //////////////////////////////
  243.   // format the html response //
  244.   //////////////////////////////
  245.   String sResponse,sHeader;
  246.  
  247.   ///////////////////////////////
  248.   // 404 for non-matching path //
  249.   ///////////////////////////////
  250.   if(sPath!="/")
  251.   {
  252.     sResponse="<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>";
  253.    
  254.     sHeader  = "HTTP/1.1 404 Not found\r\n";
  255.     sHeader += "Content-Length: ";
  256.     sHeader += sResponse.length();
  257.     sHeader += "\r\n";
  258.     sHeader += "Content-Type: text/html\r\n";
  259.     sHeader += "Connection: close\r\n";
  260.     sHeader += "\r\n";
  261.   }
  262.   //////////////////////////
  263.   // format the html page //
  264.   //////////////////////////
  265.   else
  266.   {
  267.     ulReqcount++;
  268.     sResponse  = "<html><head><title>ESP_FastLED_Access_Point</title></head><body>";
  269. //    sResponse += "<font color=\"#FFFFF0\"><body bgcolor=\"#000000\">";  
  270.     sResponse += "<font color=\"#FFFFF0\"><body bgcolor=\"#151B54\">";  
  271.     sResponse += "<FONT SIZE=-1>";
  272.     sResponse += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
  273.     sResponse += "<h1>ESP FastLED DemoReel 100<br>";
  274.     sResponse += " Light Controller</h1>";
  275.  
  276. /*  this creates a list with ON / OFF buttons
  277.     // &nbsp is a non-breaking space; moves next character over
  278.     sResponse += "<p>Rainbow &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION1ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION1OFF\"><button>--OFF--</button></a><br>";
  279.     sResponse += "<p>Rainbow Glitter<a href=\"?pin=FUNCTION2ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION2OFF\"><button>--OFF--</button></a><br>";
  280.     sResponse += "<p>Confetti &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION3ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION3OFF\"><button>--OFF--</button></a><br>";
  281.     sResponse += "<p>Sinelon &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION4ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION4OFF\"><button>--OFF--</button></a><br>";
  282.     sResponse += "<p>Juggle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION5ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION5OFF\"><button>--OFF--</button></a></p>";
  283.     sResponse += "<p>BPM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION6ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION6OFF\"><button>--OFF--</button></a></p>";
  284.     sResponse += "<p>Function 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION7ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION7OFF\"><button>--OFF--</button></a></p><br>";
  285. */
  286. //  This is a nice drop down menue
  287.     sResponse += "<FONT SIZE=+1>";
  288.     sResponse += "<form>";
  289. //    sResponse += "Select Animation<br>";
  290.     sResponse += "<p>Select:</p>";
  291.     sResponse += "<select name=\"sCmd\" size=\"7\" >";
  292.     sResponse += "<option value=\"FUNCTION1OFF\">All OFF</option>";
  293.     sResponse += "<option value=\"FUNCTION1ON\"selected>Rainbow</option>";
  294.     sResponse += "<option value=\"FUNCTION2ON\">Rainbow Glitter</option>";
  295.     sResponse += "<option value=\"FUNCTION3ON\">Confetti</option>";
  296.     sResponse += "<option value=\"FUNCTION4ON\">Sinelon</option>";
  297.     sResponse += "<option value=\"FUNCTION5ON\">Juggle</option>";
  298.     sResponse += "<option value=\"FUNCTION6ON\">BPM</option><br>";
  299.     sResponse += "</select>";
  300.     sResponse += "<br><br>";
  301.     sResponse += "<input type= submit>";
  302.     sResponse += "</form>";
  303. //    sResponse += "<FONT SIZE=-1>";
  304.  
  305. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  306. // Slider          this works, however I got http://192.168.4.1/sCmd?FUNCTION_200=80  and the page was not found
  307. //                 I needed to take the FUNCTION_200=80 apart and call only FUNCTION_200 and assign
  308. //                 the value (=80) in "react on parameters" (line 512) to new_BRIGHTNESS
  309.  
  310. sResponse += "</p>";
  311. sResponse += "<form action=\"?sCmd\" >";    // ?sCmd forced the '?' at the right spot  
  312. sResponse += "<BR>Brightness &nbsp;&nbsp";  // perhaps we can show here the current value
  313. sResponse += round(new_BRIGHTNESS /2.5);    // this is just a scale depending on the max value; round for better readability
  314. sResponse += " %";
  315. sResponse += "<BR>";
  316. sResponse += "<input style=\"width:200px; height:50px\" type=\"range\" name=\"=FUNCTION_200\" id=\"cmd\" value=\"";   // '=' in front of FUNCTION_200 forced the = at the right spot
  317. sResponse += BRIGHTNESS;
  318. sResponse += "\" min=10 max=250 step=10 onchange=\"showValue(points)\" />";
  319. sResponse += "<BR><BR>";
  320. sResponse += "<input type=\"submit\">";
  321. sResponse += "</form>";
  322. sResponse += "<p>";
  323. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  324.  
  325.  sResponse += "<FONT SIZE=-1>";
  326.  
  327.  
  328.     /////////////////////////
  329.     // react on parameters //
  330.     /////////////////////////
  331.     if (sCmd.length()>0)
  332.     {
  333.       // write received command to html page
  334.  //     sResponse += "Command: " + sCmd + "<BR>";
  335.      
  336.       // switch the animiation (based on your choice in the case statement (main loop)
  337.       if(sCmd.indexOf("FUNCTION1ON")>=0)
  338.       {
  339.         Serial.println("1 ON");
  340.         ledMode = 2;
  341.       }
  342.       else if(sCmd.indexOf("FUNCTION1OFF")>=0)
  343.       {
  344.         Serial.println("1 OFF");
  345.         ledMode = 1;
  346.       }
  347.  
  348.       if(sCmd.indexOf("FUNCTION2ON")>=0)
  349.       {
  350.          Serial.println("2 ON");
  351.         ledMode = 3;
  352.       }
  353.       else if(sCmd.indexOf("FUNCTION2OFF")>=0)
  354.       {
  355.         Serial.println("2 OFF");
  356.         ledMode = 1;
  357.       }
  358.  
  359.       if(sCmd.indexOf("FUNCTION3ON")>=0)
  360.       {
  361.         Serial.println("3 ON");
  362.         ledMode = 4;
  363.  
  364.       }
  365.       else if(sCmd.indexOf("FUNCTION3OFF")>=0)
  366.       {
  367.         Serial.println("3 OFF");
  368.         ledMode = 1;
  369.  
  370.       }
  371.       if(sCmd.indexOf("FUNCTION4ON")>=0)
  372.       {
  373.         Serial.println("4 ON");
  374.         ledMode = 5;
  375.  
  376.       }
  377.       else if(sCmd.indexOf("FUNCTION4OFF")>=0)
  378.       {
  379.         Serial.println("4 OFF");
  380.         ledMode = 1;
  381.  
  382.       }
  383.       if(sCmd.indexOf("FUNCTION5ON")>=0)
  384.       {
  385.          Serial.println("5 ON");
  386.         ledMode = 6;
  387.  
  388.       }
  389.       else if(sCmd.indexOf("FUNCTION5OFF")>=0)
  390.       {
  391.         Serial.println("5 OFF");
  392.         ledMode = 1;
  393.  
  394.       }
  395.  
  396.       if(sCmd.indexOf("FUNCTION6ON")>=0)
  397.       {
  398.          Serial.println("6 ON");
  399.         ledMode = 7;
  400.  
  401.       }
  402.       else if(sCmd.indexOf("FUNCTION6OFF")>=0)
  403.       {
  404.         Serial.println("6 OFF");
  405.         ledMode = 1;
  406.  
  407.       }
  408.       if(sCmd.indexOf("FUNCTION7ON")>=0)
  409.       {
  410.         Serial.println("7 ON");
  411.         ledMode = 8;
  412.  
  413.       }
  414.       else if(sCmd.indexOf("FUNCTION7OFF")>=0)
  415.       {
  416.          Serial.println("7 OFF");
  417.         ledMode = 1;
  418.  
  419.       }
  420.  
  421. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  422. // oh well, I was a bit frustrated. Came up with the idea to make
  423. // 10 digits increments and let the URL (not) react on it.
  424. // However, I was able to assign a new_BRIGHTNESS value;
  425. // what after all serves the purpose. Maybe someone comes up with
  426. // a more ellegant way - HOPEFULLY
  427. // (more than 400 have downloaded my code but nobody felt the need  
  428. // to help. wtf - this is my very first attempt on HTML !
  429. // Guys, I'm a simple electrician, so PLEASE help  :(          )
  430.  
  431. // do not call a new page when the slider is moved, but assign the new value
  432. // to BRIGHTNESS (this is done in "output parameters to serial", line 314
  433.  
  434.       if(sCmd.indexOf("FUNCTION_200=20")>=0) { }
  435.       if(sCmd.indexOf("FUNCTION_200=30")>=0) { }
  436.       if(sCmd.indexOf("FUNCTION_200=40")>=0) { }
  437.       if(sCmd.indexOf("FUNCTION_200=50")>=0) { }
  438.       if(sCmd.indexOf("FUNCTION_200=60")>=0) { }
  439.       if(sCmd.indexOf("FUNCTION_200=70")>=0) { }
  440.       if(sCmd.indexOf("FUNCTION_200=80")>=0) { }
  441.       if(sCmd.indexOf("FUNCTION_200=90")>=0) { }
  442.       if(sCmd.indexOf("FUNCTION_200=100")>=0) { }
  443.       if(sCmd.indexOf("FUNCTION_200=110")>=0) { }
  444.       if(sCmd.indexOf("FUNCTION_200=120")>=0) { }
  445.       if(sCmd.indexOf("FUNCTION_200=130")>=0) { }
  446.       if(sCmd.indexOf("FUNCTION_200=140")>=0) { }
  447.       if(sCmd.indexOf("FUNCTION_200=150")>=0) { }
  448.       if(sCmd.indexOf("FUNCTION_200=160")>=0) { }
  449.       if(sCmd.indexOf("FUNCTION_200=170")>=0) { }
  450.       if(sCmd.indexOf("FUNCTION_200=180")>=0) { }
  451.       if(sCmd.indexOf("FUNCTION_200=190")>=0) { }
  452.       if(sCmd.indexOf("FUNCTION_200=200")>=0) { }
  453.       if(sCmd.indexOf("FUNCTION_200=210")>=0) { }
  454.       if(sCmd.indexOf("FUNCTION_200=220")>=0) { }
  455.       if(sCmd.indexOf("FUNCTION_200=230")>=0) { }
  456.       if(sCmd.indexOf("FUNCTION_200=240")>=0) { }
  457.       if(sCmd.indexOf("FUNCTION_200=250")>=0) { }
  458. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  459.  
  460.     } // end sCmd.length()>0
  461.    
  462.    
  463. //    sResponse += "<FONT SIZE=-2>";
  464. //    sResponse += "<BR>clicks on page =";
  465. //    sResponse += ulReqcount;
  466.     sResponse += "<BR>";
  467.     sResponse += "<BR>";
  468.     sResponse += "Powered by FastLED<BR><BR>";
  469.     sResponse += "<FONT SIZE=-2>";
  470.     sResponse += "<font color=\"#FFDE00\">";
  471.     sResponse += "DemoReel 100 by Mark Kriegsman<BR>";
  472.     sResponse += "Webserver by Stefan Thesen<BR>";
  473.     sResponse += "<font color=\"#FFFFF0\">";
  474.     sResponse += "Gyro Gearloose &nbsp;&nbsp;Feb 2016<BR>";
  475.     sResponse += "</body></html>";
  476.     sHeader  = "HTTP/1.1 200 OK\r\n";
  477.     sHeader += "Content-Length: ";
  478.     sHeader += sResponse.length();
  479.     sHeader += "\r\n";
  480.     sHeader += "Content-Type: text/html\r\n";
  481.     sHeader += "Connection: close\r\n";
  482.     sHeader += "\r\n";
  483.   }
  484.  
  485.   // Send the response to the client
  486.   client.print(sHeader);
  487.   client.print(sResponse);
  488.  
  489.  
  490.   // and stop the client
  491.   client.stop();
  492.   Serial.println("Client disonnected");  
  493.   }  // end of web server
  494.  
  495. /// END of complete web server //////////////////////////////////////////////////////////////////
  496.  
  497. // LED animations ###############################################################################
  498. void all_off() {
  499.   fill_solid(leds, NUM_LEDS, CRGB::Black);
  500. //  show_at_max_brightness_for_power();
  501. //  delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);  
  502.   FastLED.show();
  503.   FastLED.delay(1000/FRAMES_PER_SECOND);
  504. }
  505.  
  506. void rainbow()
  507. {
  508.   // FastLED's built-in rainbow generator
  509.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  510.   fill_rainbow( leds, NUM_LEDS, gHue, 7);
  511.   show_at_max_brightness_for_power();
  512.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  513. //  FastLED.show();  
  514. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  515. }
  516.  
  517. void rainbowWithGlitter()
  518. {
  519.   // built-in FastLED rainbow, plus some random sparkly glitter
  520.   rainbow();
  521.   addGlitter(80);
  522. }
  523.  
  524. void addGlitter( fract8 chanceOfGlitter)
  525. {
  526.   if( random8() < chanceOfGlitter) {
  527.     leds[ random16(NUM_LEDS) ] += CRGB::White;
  528.   }
  529. }
  530.  
  531. void confetti()
  532. {
  533.   // random colored speckles that blink in and fade smoothly
  534.   fadeToBlackBy( leds, NUM_LEDS, 10);
  535.   int pos = random16(NUM_LEDS);
  536.   leds[pos] += CHSV( gHue + random8(64), 200, 255);
  537.   show_at_max_brightness_for_power();
  538.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  539. //  FastLED.show();  
  540. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  541. }
  542.  
  543. void sinelon()
  544. {
  545.   // a colored dot sweeping back and forth, with fading trails
  546.   fadeToBlackBy( leds, NUM_LEDS, 20);
  547.   int pos = beatsin16(13,0,NUM_LEDS);
  548.   leds[pos] += CHSV( gHue, 255, 192);
  549.   show_at_max_brightness_for_power();
  550.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  551. //  FastLED.show();  
  552. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  553. }
  554.  
  555. void bpm()
  556. {
  557.   // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  558.   uint8_t BeatsPerMinute = 62;
  559.   CRGBPalette16 palette = PartyColors_p;
  560.   uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  561.   for( int i = 0; i < NUM_LEDS; i++) { //9948
  562.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  563.   }
  564.   show_at_max_brightness_for_power();
  565.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  566. //  FastLED.show();  
  567. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  568. }
  569.  
  570. void juggle() {
  571.   // eight colored dots, weaving in and out of sync with each other
  572.   fadeToBlackBy( leds, NUM_LEDS, 20);
  573.   byte dothue = 0;
  574.   for( int i = 0; i < 8; i++) {
  575.     leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
  576.     dothue += 32;
  577.   }
  578.   show_at_max_brightness_for_power();
  579.   delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  580. //  FastLED.show();  
  581. //  FastLED.delay(1000/FRAMES_PER_SECOND);
  582. }
  583. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement