Guest User

Untitled

a guest
Jun 8th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.74 KB | None | 0 0
  1. /* Garrett Durland
  2. https://www.youtube.com/watch?time_continue=2&v=3zQ8qC1KQgU
  3.  
  4. Additions:
  5. - Added SPEED slider
  6. - Took out long variable names [FUNTCION1ON] are now [F_1] to avoid serial character overflow
  7. - Cleaned up the code for better readability
  8. - Gyro Gearloose, Feb. 29, 2016
  9.  
  10. */
  11. #include "FastLED.h"
  12. FASTLED_USING_NAMESPACE
  13.  
  14. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  15. #warning "Requires FastLED 3.1 or later; check github for latest code."
  16. #endif
  17.  
  18. #define LED_PIN 4
  19. //#define CLOCK_PIN 5
  20. //#define LED_TYPE APA102
  21. //#define COLOR_ORDER BGR
  22. #define LED_TYPE WS2812B
  23. #define COLOR_ORDER GRB
  24. #define MILLI_AMPERE 2000 // IMPORTANT: set here the max milli-Amps of your power supply 5V 2A = 2000
  25. int FRAMES_PER_SECOND = 100; // here you can control the speed.
  26. int ledMode = 2; // this is the starting palette
  27. const uint8_t kMatrixWidth = 16;
  28. const uint8_t kMatrixHeight = 16;
  29. const bool kMatrixSerpentineLayout = true;
  30. int BRIGHTNESS = 128; // this is half brightness
  31. int new_BRIGHTNESS = 128; // shall be initially the same as brightness
  32. int SPEED = 100; // around half speed
  33. int new_SPEED = 100;
  34.  
  35. //--Test SmartMatrix stuff------------------------------
  36. #define MATRIX_HEIGHT kMatrixHeight
  37. #define MATRIX_WIDTH kMatrixWidth
  38. const int MATRIX_CENTER_X = MATRIX_WIDTH / 2;
  39. const int MATRIX_CENTER_Y = MATRIX_HEIGHT / 2;
  40. const byte MATRIX_CENTRE_X = MATRIX_CENTER_X - 1;
  41. const byte MATRIX_CENTRE_Y = MATRIX_CENTER_Y - 1;
  42. const uint16_t NUM_LEDS = MATRIX_WIDTH * MATRIX_HEIGHT;
  43. uint16_t XY(uint8_t x, uint8_t y);
  44.  
  45. //added sm int's for overlay effects
  46. int oe1 = 0;
  47. int oe2 = 0;
  48.  
  49.  
  50. //--------------------------
  51.  
  52. #include <ESP8266WiFi.h>
  53. // comes with Huzzah installation. Enter in Arduino settings:
  54. // http://arduino.esp8266.com/package_esp8266com_index.json
  55.  
  56. //!!!!!!!!!!!!!!!!!
  57. //#define USE_AP // <- select here by commenting/uncommenting
  58. //!!!!!!!!!!!!!!!!!
  59.  
  60. #ifdef USE_AP
  61. const char* ssid = "[email protected]";
  62. const char* password = "12345678"; // set to "" for open access point w/o password; or any other pw (min length = 8 characters)
  63.  
  64. #else
  65. const char* ssid = "SSID";
  66. const char* password = "password";
  67. #endif
  68.  
  69. unsigned long ulReqcount;
  70. unsigned long ulReconncount;
  71.  
  72. WiFiServer server(80); // Create an instance of the server on Port 80
  73.  
  74. // This example combines two features of FastLED to produce a remarkable range of
  75. // effects from a relatively small amount of code. This example combines FastLED's
  76. // color palette lookup functions with FastLED's Perlin/simplex noise generator, and
  77. // the combination is extremely powerful.
  78. //
  79. // You might want to look at the "ColorPalette" and "Noise" examples separately
  80. // if this example code seems daunting.
  81. //
  82. //
  83. // The basic setup here is that for each frame, we generate a new array of
  84. // 'noise' data, and then map it onto the LED matrix through a color palette.
  85. //
  86. // Periodically, the color palette is changed, and new noise-generation parameters
  87. // are chosen at the same time. In this example, specific noise-generation
  88. // values have been selected to match the given color palettes; some are faster,
  89. // or slower, or larger, or smaller than others, but there's no reason these
  90. // parameters can't be freely mixed-and-matched.
  91. //
  92. // In addition, this example includes some fast automatic 'data smoothing' at
  93. // lower noise speeds to help produce smoother animations in those cases.
  94. //
  95. // The FastLED built-in color palettes (Forest, Clouds, Lava, Ocean, Party) are
  96. // used, as well as some 'hand-defined' ones, and some proceedurally generated
  97. // palettes.
  98.  
  99.  
  100. #define NUM_LEDS (kMatrixWidth * kMatrixHeight)
  101. #define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
  102.  
  103. // The leds
  104. CRGB leds[kMatrixWidth * kMatrixHeight];
  105.  
  106. // The 16 bit version of our coordinates
  107. static uint16_t x;
  108. static uint16_t y;
  109. static uint16_t z;
  110.  
  111. // We're using the x/y dimensions to map to the x/y pixels on the matrix. We'll
  112. // use the z-axis for "time". speed determines how fast time moves forward. Try
  113. // 1 for a very slow moving effect, or 60 for something that ends up looking like
  114. // water.
  115. uint16_t speed = 20; // speed is set dynamically once we've started up
  116.  
  117. // Scale determines how far apart the pixels in our noise matrix are. Try
  118. // changing these values around to see how it affects the motion of the display. The
  119. // higher the value of scale, the more "zoomed out" the noise iwll be. A value
  120. // of 1 will be so zoomed in, you'll mostly see solid colors.
  121. uint16_t scale = 30; // scale is set dynamically once we've started up
  122.  
  123. // This is the array that we keep our computed noise values in
  124. uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
  125. CRGBPalette16 currentPalette( CRGB::Black );
  126.  
  127. CRGBPalette16 targetPalette( CRGB::Black );
  128. uint8_t colorLoop = 1;
  129.  
  130. void setup() {
  131. ulReqcount=0; // setup globals for Webserver
  132. ulReconncount=0;
  133. // Initialize our coordinates to some random values
  134. x = random16();
  135. y = random16();
  136. z = random16();
  137. Serial.begin(9600);
  138. delay(1);
  139. // inital connect
  140.  
  141. #ifdef USE_AP
  142. // AP mode
  143. WiFi.mode(WIFI_AP);
  144. IPAddress local_ip(192,168,3,1);
  145. IPAddress gateway(192,168,3,1);
  146. IPAddress subnet(255,255,255,0);
  147. WiFi.softAPConfig(local_ip, gateway, subnet);
  148.  
  149. WiFi.softAP(ssid, password);
  150. server.begin();
  151. // end ACCESS-Point setup ---------------------------------------------------------------------------------------------------
  152.  
  153. #else
  154.  
  155. // WEB SERVER setup ---------------------------------------------------------------------------------------------------------
  156. // inital connect
  157. WiFi.mode(WIFI_STA);
  158. WiFiStart();
  159. // end WEB SERVER setup -----------------------------------------------------------------------------------------------------
  160. #endif
  161.  
  162. delay(1000); //safety delay
  163. LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS).setCorrection(DirectSunlight);
  164. //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, LED_COUNT).setCorrection(DirectSunlight);
  165. FastLED.setBrightness(BRIGHTNESS);
  166. set_max_power_in_volts_and_milliamps(5, MILLI_AMPERE);
  167. }
  168.  
  169. void WiFiStart()
  170. {
  171.  
  172. // Connect to WiFi network
  173. Serial.println();
  174. Serial.println();
  175. Serial.print("Connecting to ");
  176. Serial.println(ssid);
  177.  
  178. WiFi.begin(ssid, password);
  179.  
  180. while (WiFi.status() != WL_CONNECTED) {
  181. delay(500);
  182. Serial.print(".");
  183. }
  184. Serial.println("");
  185. Serial.println("WiFi connected");
  186.  
  187. // Start the server
  188. server.begin();
  189. Serial.println("Server started");
  190.  
  191. // Print the IP address
  192. Serial.println(WiFi.localIP());
  193. }
  194.  
  195. // Fill the x/y array of 8-bit noise values using the inoise8 function.
  196. void fillnoise8() {
  197. // If we're runing at a low "speed", some 8-bit artifacts become visible
  198. // from frame-to-frame. In order to reduce this, we can do some fast data-smoothing.
  199. // The amount of data smoothing we're doing depends on "speed".
  200. uint8_t dataSmoothing = 0;
  201. if( speed < 50) {
  202. dataSmoothing = 200 - (speed * 4);
  203. }
  204.  
  205. for(int i = 0; i < MAX_DIMENSION; i++) {
  206. int ioffset = scale * i;
  207. for(int j = 0; j < MAX_DIMENSION; j++) {
  208. int joffset = scale * j;
  209.  
  210. uint8_t data = inoise8(x + ioffset,y + joffset,z);
  211.  
  212. // The range of the inoise8 function is roughly 16-238.
  213. // These two operations expand those values out to roughly 0..255
  214. // You can comment them out if you want the raw noise data.
  215. data = qsub8(data,16);
  216. data = qadd8(data,scale8(data,39));
  217.  
  218. if( dataSmoothing ) {
  219. uint8_t olddata = noise[i][j];
  220. uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);
  221. data = newdata;
  222. }
  223.  
  224. noise[i][j] = data;
  225. }
  226. }
  227.  
  228. z += speed;
  229.  
  230. // apply slow drift to X and Y, just for visual variation.
  231. x += speed / 8;
  232. y -= speed / 16;
  233. }
  234.  
  235. void mapNoiseToLEDsUsingPalette()
  236. {
  237. static uint8_t ihue=0;
  238.  
  239. for(int i = 0; i < kMatrixWidth; i++) {
  240. for(int j = 0; j < kMatrixHeight; j++) {
  241. // We use the value at the (i,j) coordinate in the noise
  242. // array for our brightness, and the flipped value from (j,i)
  243. // for our pixel's index into the color palette.
  244.  
  245. uint8_t index = noise[j][i];
  246. uint8_t bri = noise[i][j];
  247.  
  248. // if this palette is a 'loop', add a slowly-changing base value
  249. if( colorLoop) {
  250. index += ihue;
  251. }
  252.  
  253. // brighten up, as the color palette itself often contains the
  254. // light/dark dynamic range desired
  255. if( bri > 127 ) {
  256. bri = 255;
  257. } else {
  258. bri = dim8_raw( bri * 2);
  259. }
  260.  
  261. CRGB color = ColorFromPalette( currentPalette, index, bri);
  262. leds[XY(i,j)] = color;
  263. }
  264. }
  265.  
  266. ihue+=1;
  267. }
  268.  
  269.  
  270. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  271. void loop() {
  272. webserver();
  273. // Periodically choose a new palette, speed, and scale
  274. ChangePaletteAndSettingsPeriodically();
  275. // Crossfade current palette slowly toward the target palette
  276. //
  277. // Each time that nblendPaletteTowardPalette is called, small changes
  278. // are made to currentPalette to bring it closer to matching targetPalette.
  279. // You can control how many changes are made in each call:
  280. // - the default of 24 is a good balance
  281. // - meaningful values are 1-48. 1=veeeeeeeery slow, 48=quickest
  282. // - "0" means do not change the currentPalette at all; freeze
  283. uint8_t maxChanges = 24;
  284. nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);
  285.  
  286. // generate noise data
  287. fillnoise8();
  288.  
  289. // convert the noise data to colors in the LED array
  290. // using the current palette
  291. mapNoiseToLEDsUsingPalette();
  292. if (oe1 == 1){
  293. Caleidoscope1();
  294. }
  295. if (oe2 == 1){
  296. addGlitter(50);
  297. }
  298.  
  299. show_at_max_brightness_for_power();
  300.  
  301.  
  302. delay_at_max_brightness_for_power(1000/FRAMES_PER_SECOND);
  303. }
  304. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  305.  
  306. void webserver() { /// complete web server (same for access point) ////////////////////////////////////////////////////////
  307. // Check if a client has connected
  308. WiFiClient client = server.available();
  309. if (!client)
  310. {
  311. return;
  312. }
  313.  
  314. // Wait until the client sends some data
  315. Serial.println("new client");
  316. unsigned long ultimeout = millis()+250;
  317. while(!client.available() && (millis()<ultimeout) )
  318. {
  319. delay(1);
  320. }
  321. if(millis()>ultimeout)
  322. {
  323. Serial.println("client connection time-out!");
  324. return;
  325. }
  326.  
  327. // Read the first line of the request
  328.  
  329. String sRequest = client.readStringUntil('\r');
  330. Serial.println(sRequest);
  331. client.flush();
  332.  
  333. // stop client, if request is empty
  334. if(sRequest=="")
  335. {
  336. Serial.println("empty request! - stopping client");
  337. client.stop();
  338. return;
  339. }
  340.  
  341. // get path; end of path is either space or ?
  342. // Syntax is e.g. GET /?pin=MOTOR1STOP HTTP/1.1
  343. String sPath="",sParam="", sCmd="";
  344. String sGetstart="GET ";
  345. int iStart,iEndSpace,iEndQuest;
  346. iStart = sRequest.indexOf(sGetstart);
  347.  
  348.  
  349. if (iStart>=0)
  350. {
  351. iStart+=+sGetstart.length();
  352. iEndSpace = sRequest.indexOf(" ",iStart);
  353. iEndQuest = sRequest.indexOf("?",iStart);
  354.  
  355. // are there parameters?
  356. if(iEndSpace>0)
  357. {
  358. if(iEndQuest>0)
  359. {
  360. // there are parameters
  361. sPath = sRequest.substring(iStart,iEndQuest);
  362. sParam = sRequest.substring(iEndQuest,iEndSpace);
  363. }
  364. else
  365. {
  366. // NO parameters
  367. sPath = sRequest.substring(iStart,iEndSpace);
  368. }
  369. }
  370. }
  371.  
  372. ///////////////////////////////////////////////////////////////////////////////
  373. // output parameters to serial, you may connect e.g. an Arduino and react on it
  374. ///////////////////////////////////////////////////////////////////////////////
  375. if(sParam.length()>0)
  376. { // output parameters
  377. int iEqu=sParam.indexOf("=");
  378. if(iEqu>=0)
  379. { // is there a message?
  380. sCmd = sParam.substring(iEqu+1,sParam.length());
  381. // Serial.print("We are in output Parameters, value is: ");
  382.  
  383. int iEqu_bright=sParam.indexOf("200");
  384. if (iEqu_bright>=0)
  385. {
  386. sCmd = sParam.substring(iEqu+1,sParam.length()); // BRIGHTNESS
  387. Serial.println(sCmd);
  388. char carray[4]; // values 0..255 = 3 digits; array = digits + 1
  389. sCmd.toCharArray(carray, sizeof(carray)); // convert char to the array
  390. new_BRIGHTNESS = atoi(carray); // atoi() converts an ascii character array to an integer
  391. if (new_BRIGHTNESS == 0) {new_BRIGHTNESS = BRIGHTNESS; }
  392. BRIGHTNESS = new_BRIGHTNESS;
  393. FastLED.setBrightness(new_BRIGHTNESS);
  394. Serial.print("new Brightness: ");
  395. Serial.println(new_BRIGHTNESS);
  396. }
  397.  
  398. // space for RGB (300, 400, 500)
  399.  
  400. int iEqu_speed=sParam.indexOf("600");
  401. if (iEqu_speed>=0)
  402. {
  403. sCmd = sParam.substring(iEqu+1,sParam.length()); // speed
  404. // Serial.print("We are in SPEED, value is: ");
  405. Serial.println(sCmd);
  406. char carray[4]; // values 0..255 = 3 digits; array = digits + 1
  407. sCmd.toCharArray(carray, sizeof(carray)); // convert char to the array
  408. new_SPEED = atoi(carray); // atoi() converts an ascii character array to an integer
  409. if (new_SPEED == 0) {new_SPEED = SPEED; } // if something else is selected (no change in brightness)
  410. SPEED = new_SPEED;
  411. FRAMES_PER_SECOND = SPEED;
  412. // FastLED.setMaxRefreshRate(new_SPEED); // thought this would work :(
  413.  
  414. Serial.print("new FPS: ");
  415. Serial.println(SPEED);
  416.  
  417. }
  418.  
  419. } // end is there a message?
  420. } // end output Parameters
  421.  
  422.  
  423. //////////////////////////////
  424. // format the html response //
  425. //////////////////////////////
  426. String sResponse,sHeader;
  427.  
  428. ///////////////////////////////
  429. // 404 for non-matching path //
  430. ///////////////////////////////
  431. if(sPath!="/")
  432. {
  433. 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>";
  434.  
  435. sHeader = "HTTP/1.1 404 Not found\r\n";
  436. sHeader += "Content-Length: ";
  437. sHeader += sResponse.length();
  438. sHeader += "\r\n";
  439. sHeader += "Content-Type: text/html\r\n";
  440. sHeader += "Connection: close\r\n";
  441. sHeader += "\r\n";
  442. }
  443. //////////////////////////
  444. // format the html page //
  445. //////////////////////////
  446. else
  447. {
  448. ulReqcount++;
  449. sResponse = "<html><head><title>ESP_FastLED_Access_Point</title></head><body>";
  450. // sResponse += "<font color=\"#FFFFF0\"><body bgclror=\"#000000\">";
  451. sResponse += "<font color=\"#FFFFF0\"><body bgcolor=\"#151B54\">";
  452. sResponse += "<FONT SIZE=-1>";
  453. sResponse += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
  454. sResponse += "<h1>ESP FastLED Noise Plus Palette</h1><br>";
  455. sResponse += " <h2>Overlay Effects</h2>";
  456.  
  457. /* this creates a list with ON / OFF buttons
  458. // &nbsp is a non-breaking space; moves next character over
  459. sResponse += "<p>Caleidoscope &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>";
  460. */sResponse += "<p>Caleidoscope &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>";
  461. sResponse += "<p>AddGlitter &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"?pin=FUNCTION2ON\"><button>--ON--</button></a>&nbsp;<a href=\"?pin=FUNCTION2OFF\"><button>--OFF--</button></a><br>";
  462. /*sResponse += "<p>Caleidoscope6 &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>";
  463. 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>";
  464. 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>";
  465. 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>";
  466. */
  467.  
  468. // This is a nice drop down menue
  469. sResponse += "<FONT SIZE=+1>";
  470. sResponse += "<form>";
  471. // sResponse += "Select Animation<br>";
  472. sResponse += "<p>Select Palette:</p>";
  473. sResponse += "<select name=\"sCmd\" size=\"10\" >";
  474. sResponse += "<option value=\"F_0\">All OFF</option>";
  475. sResponse += "<option value=\"F_1\">2 Random Colors</option>";
  476. sResponse += "<option value=\"F_2\">3 Random Colors</option>";
  477. sResponse += "<option value=\"F_3\">Purple & Green</option>";
  478. sResponse += "<option value=\"F_4\"selected>Black & White</option>";
  479. sResponse += "<option value=\"F_5\">Forest Colors</option>";
  480. sResponse += "<option value=\"F_6\">Cloud Colors</option>";
  481. sResponse += "<option value=\"F_7\">Lava Colors</option>";
  482. sResponse += "<option value=\"F_8\">Ocean Colors</option>";
  483. sResponse += "<option value=\"F_9\">Party Colors</option><br>";
  484. sResponse += "</select>";
  485. sResponse += "<br><br>";
  486. sResponse += "<input type= submit value=\"Show the MAGIC !\">";
  487. sResponse += "</form>";
  488. sResponse += "<br><br>";
  489. // sResponse += "<FONT SIZE=-1>";
  490.  
  491. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  492. // Slider BRIGHTNESS
  493. sResponse += "</p>";
  494. sResponse += "<form action=\"?sCmd\" >"; // ?sCmd forced the '?' at the right spot
  495. sResponse += "<input type=\"submit\" value=\"SET\">";
  496. sResponse += "&nbsp BRIGHTNESS &nbsp;&nbsp"; // perhaps we can show here the current value
  497. sResponse += round(new_BRIGHTNESS /2.5); // this is just a scale depending on the max value; round for better readability
  498. sResponse += " %";
  499. sResponse += "<BR>";
  500. sResponse += "<input style=\"width:250px; height:50px\" type=\"range\" name=\"=F_200\" id=\"cmd\" value=\""; // '=' in front of F__200 forced the = at the right spot
  501. sResponse += BRIGHTNESS;
  502. sResponse += "\" min=10 max=250 step=10 onchange=\"showValue(points)\" />";
  503. sResponse += "</form>";
  504. sResponse += "<p>";
  505. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  506. // Slider SPEED
  507. sResponse += "</p>";
  508. sResponse += "<form action=\"?sCmd\" >"; // ?sCmd forced the '?' at the right spot
  509. sResponse += "<input type=\"submit\" value=\"SET\">";
  510. sResponse += "&nbsp <font color=yellow><b>SPEED &nbsp"; // perhaps we can show here the current value
  511. sResponse += round(new_SPEED /2); // this is just a scale depending on the max value; round for better readability
  512. sResponse += " %";
  513. sResponse += "<BR>";
  514. sResponse += "<input style=\"width:250px; height:50px\" type=\"range\" name=\"=F_600\" id=\"cmd\" value=\""; // '=' in front of F__200 forced the = at the right spot
  515. sResponse += SPEED;
  516. sResponse += "\" min=20 max=400 step=20 onchange=\"showValue(points)\" />";
  517. sResponse += "</font></b>";
  518. sResponse += "</form>";
  519. sResponse += "<p>";
  520. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  521.  
  522. sResponse += "<FONT SIZE=-1>";
  523.  
  524. //////////////////////
  525. // react on parameters
  526. //////////////////////
  527. if (sCmd.length()>0)
  528. {
  529. if(sCmd.indexOf("F_0")>=0) { ledMode = 0; }
  530. if(sCmd.indexOf("F_1")>=0) { ledMode = 1; }
  531. if(sCmd.indexOf("F_2")>=0) { ledMode = 2; }
  532. if(sCmd.indexOf("F_3")>=0) { ledMode = 3; }
  533. if(sCmd.indexOf("F_4")>=0) { ledMode = 4; }
  534. if(sCmd.indexOf("F_5")>=0) { ledMode = 5; }
  535. if(sCmd.indexOf("F_6")>=0) { ledMode = 6; }
  536. if(sCmd.indexOf("F_7")>=0) { ledMode = 7; }
  537. if(sCmd.indexOf("F_8")>=0) { ledMode = 8; }
  538. if(sCmd.indexOf("F_9")>=0) { ledMode = 9; }
  539. if(sCmd.indexOf("FUNCTION1ON")>=0) { ledMode = 10; }
  540. if(sCmd.indexOf("FUNCTION1OFF")>=0) { ledMode = 11; }
  541. if(sCmd.indexOf("FUNCTION2ON")>=0) { ledMode = 12; }
  542. if(sCmd.indexOf("FUNCTION2OFF")>=0) { ledMode = 13; }
  543.  
  544. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  545. // oh well, Gyro Gearloose was a bit frustrated. He came up with the
  546. // idea to make 10 digits increments and let the URL (not) react on it.
  547. // However, he was able to assign a new_BRIGHTNESS value;
  548. // what after all serves the purpose. Maybe someone comes up with
  549. // a more ellegant way - HOPEFULLY
  550.  
  551. // do not call a new page when the slider is moved, but assign the new value
  552. // to BRIGHTNESS (this is done in "output parameters to serial", line 314
  553.  
  554. if(sCmd.indexOf("F_200=20")>=0) { }
  555. if(sCmd.indexOf("F_200=30")>=0) { }
  556. if(sCmd.indexOf("F_200=40")>=0) { }
  557. if(sCmd.indexOf("F_200=50")>=0) { }
  558. if(sCmd.indexOf("F_200=60")>=0) { }
  559. if(sCmd.indexOf("F_200=70")>=0) { }
  560. if(sCmd.indexOf("F_200=80")>=0) { }
  561. if(sCmd.indexOf("F_200=90")>=0) { }
  562. if(sCmd.indexOf("F_200=100")>=0) { }
  563. if(sCmd.indexOf("F_200=110")>=0) { }
  564. if(sCmd.indexOf("F_200=120")>=0) { }
  565. if(sCmd.indexOf("F_200=130")>=0) { }
  566. if(sCmd.indexOf("F_200=140")>=0) { }
  567. if(sCmd.indexOf("F_200=150")>=0) { }
  568. if(sCmd.indexOf("F_200=160")>=0) { }
  569. if(sCmd.indexOf("F_200=170")>=0) { }
  570. if(sCmd.indexOf("F_200=180")>=0) { }
  571. if(sCmd.indexOf("F_200=190")>=0) { }
  572. if(sCmd.indexOf("F_200=200")>=0) { }
  573. if(sCmd.indexOf("F_200=210")>=0) { }
  574. if(sCmd.indexOf("F_200=220")>=0) { }
  575. if(sCmd.indexOf("F_200=230")>=0) { }
  576. if(sCmd.indexOf("F_200=240")>=0) { }
  577. if(sCmd.indexOf("F_200=250")>=0) { }
  578. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  579.  
  580. if(sCmd.indexOf("F_600=20")>=0) { }
  581. if(sCmd.indexOf("F_600=40")>=0) { }
  582. if(sCmd.indexOf("F_600=60")>=0) { }
  583. if(sCmd.indexOf("F_600=80")>=0) { }
  584. if(sCmd.indexOf("F_600=100")>=0) { }
  585. if(sCmd.indexOf("F_600=120")>=0) { }
  586. if(sCmd.indexOf("F_600=140")>=0) { }
  587. if(sCmd.indexOf("F_600=160")>=0) { }
  588. if(sCmd.indexOf("F_600=180")>=0) { }
  589. if(sCmd.indexOf("F_600=200")>=0) { }
  590. if(sCmd.indexOf("F_600=220")>=0) { }
  591. if(sCmd.indexOf("F_600=240")>=0) { }
  592. if(sCmd.indexOf("F_600=260")>=0) { }
  593. if(sCmd.indexOf("F_600=280")>=0) { }
  594. if(sCmd.indexOf("F_600=300")>=0) { }
  595. if(sCmd.indexOf("F_600=320")>=0) { }
  596. if(sCmd.indexOf("F_600=340")>=0) { }
  597. if(sCmd.indexOf("F_600=360")>=0) { }
  598. if(sCmd.indexOf("F_600=380")>=0) { }
  599. if(sCmd.indexOf("F_600=400")>=0) { }
  600. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  601.  
  602.  
  603. } // end sCmd.length()>0
  604.  
  605.  
  606. sResponse += "<BR>";
  607. sResponse += "<BR>";
  608. sResponse += "Powered by FastLED<BR><BR>";
  609. sResponse += "<FONT SIZE=-2>";
  610. sResponse += "<font color=\"#FFDE00\">";
  611. sResponse += "Noise Plus Palette by Mark Kriegsman<BR>";
  612. sResponse += "Webserver by Stefan Thesen<BR>";
  613. sResponse += "<font color=\"#FFFFF0\">";
  614. sResponse += "Gyro Gearloose &nbsp;&nbsp;Feb 2016<BR>";
  615. sResponse += "SigmazGFX &nbsp;&nbsp;Jun 2016<BR>";
  616. sResponse += "</body></html>";
  617. sHeader = "HTTP/1.1 200 OK\r\n";
  618. sHeader += "Content-Length: ";
  619. sHeader += sResponse.length();
  620. sHeader += "\r\n";
  621. sHeader += "Content-Type: text/html\r\n";
  622. sHeader += "Connection: close\r\n";
  623. sHeader += "\r\n";
  624.  
  625. } // end Format HTML page
  626.  
  627. // Send the response to the client
  628. client.print(sHeader);
  629. client.print(sResponse);
  630.  
  631.  
  632. // and stop the client
  633. client.stop();
  634. Serial.println("Client disonnected");
  635. } // end of web server
  636.  
  637.  
  638. // There are several different palettes of colors demonstrated here.
  639. //
  640. // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
  641. // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
  642. //
  643. // Additionally, you can manually define your own color palettes, or you can write
  644. // code that creates color palettes on the fly.
  645.  
  646. // 1 = 5 sec per palette
  647. // 2 = 10 sec per palette
  648. // etc
  649. #define HOLD_PALETTES_X_TIMES_AS_LONG 2
  650.  
  651. void ChangePaletteAndSettingsPeriodically()
  652. {
  653. uint8_t maxChanges = 10;
  654. nblendPaletteTowardPalette( currentPalette, targetPalette, maxChanges);
  655. //uint8_t secondHand = ((millis() / 1000) / HOLD_PALETTES_X_TIMES_AS_LONG) % 60; //not used with webserver
  656. //static uint8_t lastSecond = 99; //not used with webserver
  657.  
  658. if (ledMode != 999) {
  659. switch (ledMode) {
  660. case 0: all_off(); break;
  661. case 1: SetupRandomPalette(); speed = 3; scale = 25; colorLoop = 1; break; //2-color palette
  662. case 2: SetupRandomPalette_g(); speed = 3; scale = 25; colorLoop = 1; break; //3-color palette
  663. case 3: SetupPurpleAndGreenPalette(); speed = 6; scale = 20; colorLoop = 1; break;
  664. case 4: SetupBlackAndWhiteStripedPalette(); speed = 4; scale = 20; colorLoop = 1; ; break;
  665. case 5: targetPalette = ForestColors_p; speed = 3; scale = 20; colorLoop = 0; break;
  666. case 6: targetPalette = CloudColors_p; speed = 4; scale = 20; colorLoop = 0; break;
  667. case 7: targetPalette = LavaColors_p; speed = 8; scale = 19; colorLoop = 0; break;
  668. case 8: targetPalette = OceanColors_p; speed = 6; scale = 25; colorLoop = 0; break;
  669. case 9: targetPalette = PartyColors_p; speed = 3; scale = 20; colorLoop = 1; break;
  670. case 10: oe1 = 1; break;
  671. case 11: oe1 = 0; break;
  672. case 12: oe2 = 1; break;
  673. case 13: oe2 = 0; break;
  674.  
  675. }
  676. }
  677. }
  678.  
  679. // This function generates a random palette that's a gradient
  680. // between four different colors. The first is a dim hue, the second is
  681. // a bright hue, the third is a bright pastel, and the last is
  682. // another bright hue. This gives some visual bright/dark variation
  683. // which is more interesting than just a gradient of different hues.
  684.  
  685. // LED animations ###############################################################################
  686. void all_off() { fill_solid( targetPalette, 16, CRGB::Black);}
  687. void SetupRandomPalette()//two colors
  688. {
  689. EVERY_N_MILLISECONDS( 8000 ){ //new random palette every 8 seconds. Might have to wait for the first one to show up
  690. CRGB black = CRGB::Black;
  691. CRGB random1 = CHSV( random8(), 255, 255);
  692. CRGB random2 = CHSV( random8(), 255, 255);
  693. targetPalette = CRGBPalette16(
  694. // CRGB( random8(), 255, 32),
  695. // CHSV( random8(), 255, 255),
  696. random1,random1,black, black,
  697. random2,random2,black, black,
  698. random1,random1,black, black,
  699. random2,random2,black, black);
  700. // CHSV( random8(), 128, 255),
  701. // CHSV( random8(), 255, 255), );
  702. }
  703. }
  704. void SetupRandomPalette_g()//three colors
  705. {
  706. EVERY_N_MILLISECONDS( 8000 ){ //new random palette every 8 seconds
  707. CRGB black = CRGB::Black;
  708. CRGB random1 = CHSV( random8(), 255, 255);
  709. CRGB random2 = CHSV( random8(), 200, 100);
  710. CRGB random3 = CHSV( random8(), 150, 200);
  711. targetPalette = CRGBPalette16(
  712. // CRGB( random8(), 255, 32),
  713. // CHSV( random8(), 255, 255),
  714. random1,random1,black, black,
  715. random2,random2,black, random3,
  716. random1,random1,black, black,
  717. random2,random2,black, random3);
  718. // CHSV( random8(), 128, 255),
  719. // CHSV( random8(), 255, 255), );
  720. }
  721. }
  722. // This function sets up a palette of purple and green stripes.
  723. void SetupPurpleAndGreenPalette()
  724. {
  725. CRGB purple = CHSV( HUE_PURPLE, 255, 255);
  726. CRGB green = CHSV( HUE_GREEN, 255, 255);
  727. CRGB black = CRGB::Black;
  728.  
  729. targetPalette = CRGBPalette16(
  730. green, green, black, black,
  731. purple, purple, black, black,
  732. green, green, black, black,
  733. purple, purple, black, black );
  734. }
  735. // This function sets up a palette of black and white stripes,
  736. // using code. Since the palette is effectively an array of
  737. // sixteen CRGB colors, the various fill_* functions can be used
  738. // to set them up.
  739. void SetupBlackAndWhiteStripedPalette()
  740. {
  741. // 'black out' all 16 palette entries...
  742. fill_solid( targetPalette, 16, CRGB::Black);
  743. // and set every eighth one to white.
  744. currentPalette[0] = CRGB::White;
  745. // currentPalette[4] = CRGB::White;
  746. currentPalette[8] = CRGB::White;
  747. // currentPalette[12] = CRGB::White;
  748. }
  749. //
  750. // Mark's xy coordinate mapping code. See the XYMatrix for more information on it.
  751. //
  752. uint16_t XY( uint8_t x, uint8_t y)
  753. {
  754. uint16_t i;
  755. if( kMatrixSerpentineLayout == false) {
  756. i = (y * kMatrixWidth) + x;
  757. }
  758. if( kMatrixSerpentineLayout == true) {
  759. if( y & 0x01) {
  760. // Odd rows run backwards
  761. uint8_t reverseX = (kMatrixWidth - 1) - x;
  762. i = (y * kMatrixWidth) + reverseX;
  763. } else {
  764. // Even rows run forwards
  765. i = (y * kMatrixWidth) + x;
  766. }
  767. }
  768. return i;
  769. }
  770. void FillLEDsFromPaletteColors(uint8_t colorIndex)
  771. {
  772. uint8_t brightness = 255;
  773.  
  774. for( int i = 0; i < NUM_LEDS; i++) {
  775. leds[i] = ColorFromPalette( currentPalette, colorIndex + sin8(i*16), brightness);
  776. colorIndex += 3;
  777. }
  778. }
  779.  
  780. void addGlitter( fract8 chanceOfGlitter)
  781. {
  782. if ( random8() < chanceOfGlitter) {
  783. leds[ random16(NUM_LEDS) ] += CRGB::White;
  784. }
  785. }
  786.  
  787. void Caleidoscope1() {
  788. for (int x = 0; x < MATRIX_CENTER_X; x++) {
  789. for (int y = 0; y < MATRIX_CENTER_Y; y++) {
  790. leds[XY(MATRIX_WIDTH - 1 - x, y)] = leds[XY(x, y)];
  791. leds[XY(MATRIX_WIDTH - 1 - x, MATRIX_HEIGHT - 1 - y)] = leds[XY(x, y)];
  792. leds[XY(x, MATRIX_HEIGHT - 1 - y)] = leds[XY(x, y)];
  793. }
  794. }
  795. }
Advertisement
Add Comment
Please, Sign In to add comment