// Program for "LampeNG" made by Go2 on 2022/08/05 // Load Wi-Fi library #include // Set web server port number to 80 WiFiServer server(80); // Variable to store the HTTP request String header; // Auxiliar variables to store the current output state String ONOFFState = "ON"; String GlittersState = "ON"; String FadeState = "OFF"; String GlittersSpeed = "2"; String FadeSpeed = "1"; int TimeTempo = 30; int count = 0; int brightness1 = 0; // how bright the LED is int brightness2 = 0; // how bright the LED is int brightness3 = 0; // how bright the LED is int brightness4 = 0; // how bright the LED is int fadeAmount1 = 10; // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255. int fadeAmount2 = 20; // how many points to fade the LED by int fadeAmount3 = 30; // how many points to fade the LED by int fadeAmount4 = 40; // how many points to fade the LED by static unsigned long lastTimeItHappened = 0; void setup() { Serial.begin(115200); // Initialize the output variables as outputs pinMode(D5, OUTPUT); // Initialize the D5 pin as an output pinMode(D6, OUTPUT); // Initialize the D6 pin as an output pinMode(D7, OUTPUT); // Initialize the D7 pin as an output pinMode(D8, OUTPUT); // Initialize the D8 pin as an output delay(2000); // 2 second delay for recovery // WIFI ACCESS POINT // ================= WiFi.mode(WIFI_AP); //Our ESP8266-12E is an AccessPoint WiFi.softAP("Go2design"); // Provide the SSID server.begin(); // Start the HTTP Server IPAddress HTTPS_ServerIP= WiFi.softAPIP(); // Obtain the IP of the Server Serial.print("Server IP is: "); // 192.168.4.1 Serial.println(HTTPS_ServerIP); } void loop(){ WiFiClient client = server.available(); // Listen for incoming clients // Call the current pattern function once, updating the 'leds' array if (millis() - lastTimeItHappened >= 1000) { // Ten seconds or more since it last happened lastTimeItHappened = millis(); count++; } if (count >= 115) // Reinit every 2mn (115 for execution of program) { ONOFFState = "ON"; GlittersState = "ON"; FadeState = "OFF"; TimeTempo = 30; count = 0; } if (count >= 1000) {count = 1;} // Reinit for limit of variable if (GlittersState == "ON") {Glitters(TimeTempo);} if (FadeState == "ON") {Fade(TimeTempo);} if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor header += c; if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println("Connection: close"); client.println(); count = 0 ; // turns the variable // push on MARCHE adress is ONOFF/off if (header.indexOf("GET /ONOFF/off") >= 0) { Serial.println("ONOFF off"); ONOFFState = "OFF"; GlittersState = "ON"; FadeState = "ON"; TimeTempo = 0; } else if (header.indexOf("GET /ONOFF/on") >= 0) { Serial.println("ONOFF on"); ONOFFState = "ON"; GlittersState = "ON"; FadeState = "OFF"; TimeTempo = 30; } else if (header.indexOf("GET /Glitters/on") >= 0) { Serial.println("Glitters on"); GlittersState = "OFF"; FadeState = "OFF"; TimeTempo = 0; } else if (header.indexOf("GET /Glitters/1") >= 0) { Serial.println("Glitters 1"); GlittersSpeed = "1"; TimeTempo = 10; } else if (header.indexOf("GET /Glitters/2") >= 0) { Serial.println("Glitters 2"); GlittersSpeed = "2"; TimeTempo = 30; } else if (header.indexOf("GET /Glitters/3") >= 0) { Serial.println("Glitters 3"); GlittersSpeed = "3"; TimeTempo = 60; } else if (header.indexOf("GET /Glitters/4") >= 0) { Serial.println("Glitters 4"); GlittersSpeed = "4"; TimeTempo = 90; } else if (header.indexOf("GET /Glitters/off") >= 0) { Serial.println("Glitter off"); ONOFFState = "ON"; GlittersState = "ON"; FadeState = "OFF"; GlittersSpeed = "2"; TimeTempo = 30; } else if (header.indexOf("GET /Fade/on") >= 0) { Serial.println("Fade on"); GlittersState = "OFF"; FadeState = "OFF"; Glitters(0); } else if (header.indexOf("GET /Fade/1") >= 0) { Serial.println("Fade 1"); FadeSpeed = "1"; TimeTempo = 30; } else if (header.indexOf("GET /Fade/2") >= 0) { Serial.println("Fade 2"); FadeSpeed = "2"; TimeTempo = 60; } else if (header.indexOf("GET /Fade/3") >= 0) { Serial.println("Fade 3"); FadeSpeed = "3"; TimeTempo = 90; } else if (header.indexOf("GET /Fade/off") >= 0) { Serial.println("Fade off"); ONOFFState = "ON"; GlittersState = "OFF"; FadeState = "ON"; FadeSpeed = "1"; TimeTempo = 30; } // Display the HTML web page client.println(""); client.println(""); client.println(""); // CSS to style the on/off buttons // Feel free to change the background-color and font-size attributes to fit your preferences client.println(""); // Web Page Heading client.println("

NG by Go²

"); if (ONOFFState=="OFF") { client.println("

"); } else if (ONOFFState=="ON"){ client.println("

"); if (GlittersState=="OFF") { client.println("

"); } else { client.println("

"); if (GlittersSpeed=="1") { client.println(""); client.println(""); client.println(""); client.println(""); } else if (GlittersSpeed=="2") { client.println(""); client.println(""); client.println(""); client.println(""); } else if (GlittersSpeed=="3") { client.println(""); client.println(""); client.println(""); client.println(""); } else if (GlittersSpeed=="4") { client.println(""); client.println(""); client.println(""); client.println(""); } } if (FadeState=="OFF") { client.println("

"); } else { client.println("

"); if (FadeSpeed=="1") { client.println(""); client.println(""); client.println(""); } else if (FadeSpeed=="2") { client.println(""); client.println(""); client.println(""); } else if (FadeSpeed=="3") { client.println(""); client.println(""); client.println(""); } } } client.println(""); // The HTTP response ends with another blank line client.println(); // Break out of the while loop break; } else { // if you got a newline, then clear currentLine currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } } } // Clear the header variable header = ""; // Close the connection client.stop(); Serial.println("Client disconnected."); Serial.println(""); } } void Glitters (int TimeTempo) { if (TimeTempo > 0) { digitalWrite(D5, HIGH); // Turn the LED on (Note that LOW is the voltage level // but actually the LED is on; this is because // it is active low on the ESP-01) delay(TimeTempo); // Wait for a second digitalWrite(D5, LOW); // Turn the LED off by making the voltage HIGH delay(TimeTempo); // Wait for two seconds (to demonstrate the active low LED) digitalWrite(D6, HIGH); // Turn the LED on (Note that LOW is the voltage level // but actually the LED is on; this is because // it is active low on the ESP-01) delay(TimeTempo); // Wait for a second digitalWrite(D6, LOW); // Turn the LED off by making the voltage HIGH delay(TimeTempo); // Wait for two seconds (to demonstrate the active low LED) digitalWrite(D7, HIGH); // Turn the LED on (Note that LOW is the voltage level // but actually the LED is on; this is because // it is active low on the ESP-01) delay(TimeTempo); // Wait for a second digitalWrite(D7, LOW); // Turn the LED off by making the voltage HIGH delay(TimeTempo); // Wait for two seconds (to demonstrate the active low LED) digitalWrite(D8, HIGH); // Turn the LED on (Note that LOW is the voltage level // but actually the LED is on; this is because // it is active low on the ESP-01) delay(TimeTempo); // Wait for a second digitalWrite(D8, LOW); // Turn the LED off by making the voltage HIGH delay(TimeTempo); // Wait for two seconds (to demonstrate the active low LED) } else { digitalWrite(D5, LOW); // Turn the LED off by making the voltage HIGH digitalWrite(D6, LOW); // Turn the LED off by making the voltage HIGH digitalWrite(D7, LOW); // Turn the LED off by making the voltage HIGH digitalWrite(D8, LOW); // Turn the LED off by making the voltage HIGH } } void Fade(int TimeTempo) { if (TimeTempo > 0) { analogWrite(D5, brightness1); // change the brightness for next time through the loop: brightness1 = brightness1 + fadeAmount1; if (brightness1 <= 0 || brightness1 >= 255) { fadeAmount1 = -fadeAmount1; } // wait to see the dimming effect delay(TimeTempo); analogWrite(D6, brightness2); // change the brightness for next time through the loop: brightness2 = brightness2 + fadeAmount2; if (brightness2 <= 0 || brightness2 >= 255) { fadeAmount2 = -fadeAmount2; } // wait to see the dimming effect delay(TimeTempo); analogWrite(D7, brightness3); // change the brightness for next time through the loop: brightness3 = brightness3 + fadeAmount3; if (brightness3 <= 0 || brightness3 >= 255) { fadeAmount3 = -fadeAmount3; } // wait to see the dimming effect delay(TimeTempo); analogWrite(D8, brightness4); // change the brightness for next time through the loop: brightness4 = brightness4 + fadeAmount4; if (brightness4 <= 0 || brightness4 >= 255) { fadeAmount4 = -fadeAmount4; } // wait to see the dimming effect delay(TimeTempo); } else { digitalWrite(D5, LOW); // Turn the LED off by making the voltage HIGH digitalWrite(D6, LOW); // Turn the LED off by making the voltage HIGH digitalWrite(D7, LOW); // Turn the LED off by making the voltage HIGH digitalWrite(D8, LOW); // Turn the LED off by making the voltage HIGH } }