From 161a4d92f8c641d0ef6af12386dea2fb666a7522 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Sat, 30 Jul 2016 18:04:44 +0200 Subject: [PATCH] Rebuilding modes and coloroptions --- lichterKette.ino | 161 ++++++++++++++++++++++++++++------------------- 1 file changed, 96 insertions(+), 65 deletions(-) diff --git a/lichterKette.ino b/lichterKette.ino index 4949fa6..a9fbd52 100644 --- a/lichterKette.ino +++ b/lichterKette.ino @@ -20,21 +20,29 @@ unsigned long interval = 0; int mode = 0; int element = 0; -int colorval1 = 0; -int colorval2 = 0; -int colorval3 = 0; +unsigned int colorval1 = 0; +unsigned int colorval2 = 0; +unsigned int colorval3 = 0; + +unsigned int primary_r = 0; +unsigned int primary_g = 0; +unsigned int primary_b = 0; + +unsigned int second_r = 0; +unsigned int second_g = 0; +unsigned int second_b = 0; String responseHTML = "" "LedControl" "

Control


" "on

off" "
run
run single
freaky" - "
0
" - "1
" - "2
" - "3
" - "4
" - "5
"; + "
0
" + "Run (once)
" + "Freaky breathe
" + "Run single
" + "Mode 4
" + "5
"; void handleOn() { @@ -74,11 +82,42 @@ void handleOff() { webServer.send(200, "text/html", responseHTML); } void handleShow() { -Serial.println(webServer.args()); + for ( uint8_t i = 0; i < webServer.args(); i++ ) { + if (webServer.argName( i ) == "num") { + char buf[3]; + webServer.arg( i ).toCharArray(buf, 3); + int num = atoi(buf); + switch (num) { + case 0: + mode = 0; + Serial.println("leds should be off here"); + break; + case 1: + mode = 1; + Serial.println("mode 1 run"); + break; + case 2: + mode = 2; + Serial.println("mode 2 runSingle"); + break; + case 3: + mode = 3; + Serial.println("mode 3 freaky breath"); + break; + case 4: + mode = 4; + Serial.println("mode 4"); + break; + } + Serial.println(num); + } + } + webServer.send(200, "text/html", responseHTML); } void setup() { strip.begin(); Serial.begin(115200); + Serial.println("Ready"); WiFi.mode(WIFI_AP); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); @@ -94,12 +133,6 @@ void setup() { webServer.on("/show", handleShow); - webServer.on("/1", handle1); - webServer.on("/2", handle2); - webServer.on("/3", handle3); - - - webServer.onNotFound([]() { webServer.send(200, "text/html", responseHTML); }); @@ -114,62 +147,60 @@ void loop() { dnsServer.processNextRequest(); webServer.handleClient(); + if (millis() - previousMillis >= interval) { + // save the last time you blinked the LED + previousMillis = millis(); - - if (millis() - previousMillis >= interval) { - // save the last time you blinked the LED - previousMillis = millis(); + switch (mode) { - switch(mode){ - - case 1: + case 1: interval = 100; - if(element 150) colorval2=0; - if(colorval1 < 30) colorval2=1; - for(int i=0;i 150) colorval2 = 0; + if (colorval1 < 30) colorval2 = 1; + for (int i = 0; i < NUMPIXELS; i++) { + strip.setPixelColor(i, strip.Color(colorval1, colorval1, colorval1)); + + } + strip.show(); + break; + case 3: + + interval = 100; + if (element < NUMPIXELS) + element++; + else + element = 0; + for (int i = 0; i < NUMPIXELS; i++) { + strip.setPixelColor(i, strip.Color(((i == element) ? 100 : 200), ((i == element) ? 100 : 50), ((i == element) ? 100 : 0))); // Moderately bright green color. + } + strip.show(); + + + default: + break; } - + + previousMillis = millis(); + } + }