diff --git a/src/main.cpp b/src/main.cpp index 6e9f8ea..4ea1a2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,41 +25,116 @@ const char* password = STAPSK; uint8_t rgb[3] = {122,122,122}; uint8_t wave = 0; int mode = 0; +int o1 = 0; //Option 1 +int o2 = 0; //Option 2 +String modenames[] = {"default", "random", "simple wave", "Multiwave", "insertionsort","bubblesort", "stalinsort","dual mulitwave with options","quicksort"}; ESP8266WebServer server(80); const int led = LED_BUILTIN; -const String postForms = "\ +String postFirstHalf = "\ \ ESP8266 Web Server POST handling\ \ +\ \ \ -

POST plain text to r


\ -
\ -
\ +
\ +
\ + LEDstrip controller\ +
\ +
\ + mode
\ +
\ + \ +
\ + \ + \ +
\ +
\ +
\ +

modes


"; + +String postSecondHalf = "\ +
\ +\ +
\ +

RGB


\ +
\ +

\ +

\ +

\ \
\ -

POST form data to g


\ -
\ -
\ +
\ +
\ +

Optional parameters


\ + \ +
\ \ \ -

POST form data to b


\ -
\ -
\ + \ +
\ \ -
\ -

POST form data to mode


\ -
\ -
\ - \ -
\ +
\ + \ \ "; +String postForms = ""; void handleRoot() { digitalWrite(led, 1); @@ -67,15 +142,26 @@ void handleRoot() { digitalWrite(led, 0); } -void handleR() { +void handleRGB() { if (server.method() != HTTP_POST) { digitalWrite(led, 1); server.send(405, "text/plain", "Method Not Allowed"); digitalWrite(led, 0); } else { String temp = server.arg("plain"); - temp.remove(0,2); - rgb[0] = temp.toInt(); + int index = 0; + while (true) { + int amp = temp.indexOf("&"); + int es = temp.indexOf("="); + if (amp != -1) { + rgb[index] = temp.substring(es+1,amp).toInt(); + temp.remove(0,amp+1); + } else { + rgb[index] = temp.substring(es+1).toInt(); + break; + } + index++; + } Serial.println(rgb[0]); Serial.println(temp); digitalWrite(led, 0); @@ -83,7 +169,7 @@ void handleR() { server.send(200, "text/html", postForms); } -void handleG() { +void handleOption1() { if (server.method() != HTTP_POST) { digitalWrite(led, 1); server.send(405, "text/plain", "Method Not Allowed"); @@ -91,9 +177,9 @@ void handleG() { } else { digitalWrite(led, 1); String temp = server.arg("plain"); - temp.remove(0,2); - rgb[1] = temp.toInt(); - Serial.println(rgb[1]); + temp.remove(0,3); + o1 = temp.toInt(); + Serial.println(o1); Serial.println(temp); digitalWrite(led, 0); } @@ -101,7 +187,7 @@ void handleG() { } -void handleB() { +void handleOption2() { if (server.method() != HTTP_POST) { digitalWrite(led, 1); server.send(405, "text/plain", "Method Not Allowed"); @@ -109,9 +195,9 @@ void handleB() { } else { digitalWrite(led, 1); String temp = server.arg("plain"); - temp.remove(0,2); - rgb[2] = temp.toInt(); - Serial.println(rgb[2]); + temp.remove(0,3); + o2 = temp.toInt(); + Serial.println(o2); Serial.println(temp); digitalWrite(led, 0); } @@ -150,6 +236,11 @@ void handleNotFound() { } void setup(void) { + String buttons = ""; + for (int i = 0; i"+modenames[i] + "
"; + } + postForms = postFirstHalf + buttons + postSecondHalf; pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) pinMode(led, OUTPUT); digitalWrite(led, 0); @@ -174,11 +265,11 @@ void setup(void) { server.on("/", handleRoot); - server.on("/r/", handleR); + server.on("/rgb/", handleRGB); - server.on("/g/", handleG); + server.on("/o1/", handleOption1); - server.on("/b/", handleB); + server.on("/o2/", handleOption2); server.on("/mode/",handleMode); @@ -189,6 +280,81 @@ void setup(void) { Serial.println("HTTP server started"); } + +int partition(int arr[],int low,int high) { + int pivot = arr[high]; + int small = low; + for (int i = low; i < high; i++) { + if (arr[i] lim) ? 1.:0.; +} +double right_light_pulse(double x,double t) { + double combined = smod(x*30,1.)+t*5; + combined = fabs(1.-2.*smod(combined,1.)); + return combined*combined; +} + +double empty_light_pulse(double x, double t) { + return 0.; +} + +double left_light_pulse(double x, double t) { + double combined = (smod(x*30,1.)-t*5); + combined = fabs(1.-2.*smod(combined,1.)); + return combined*combined; +} + void loop(void) { if(mode == 0){ pixels.clear(); // Set all pixel colors to 'off' @@ -354,6 +520,43 @@ void loop(void) { delay(1000); server.handleClient(); } + }else if(mode == 7) { + double (*r)(double, double); + double (*g)(double, double); + double (*b)(double, double); + r= &empty_light_pulse; + g = &empty_light_pulse; + b = &empty_light_pulse; + if (o1 == 0) { + r = &right_light_pulse; + } else if (o1 == 1) { + g = &right_light_pulse; + } else if (o1 == 2) { + b = &right_light_pulse; + } + if (o2 == 0) { + r = &left_light_pulse; + } else if (o2 == 1) { + g = &left_light_pulse; + } else if (o2 == 2) { + b = &left_light_pulse; + } + shadertoy(r,g,b); + }else if(mode == 8) { + int list_length = 300;//rgb[0]; + + int *arr = new int[list_length]; + + for (int i = 0; i < list_length; i++) { + arr[i] = random(65536); + pixels.setPixelColor(i,pixels.ColorHSV(arr[i])); + pixels.show(); + server.handleClient(); + } + + + quicksort(arr,0,list_length-1); + server.handleClient(); }else{ // The first NeoPixel in a strand is #0, second is 1, all the way up // to the count of pixels minus one. @@ -364,4 +567,4 @@ void loop(void) { server.handleClient(); } } -} \ No newline at end of file +}