I have two button "Pattern1" and "Pattern2" , I want to run 2 LED pattern by using esp8266 and web browser, If I click on "Pattern1" button the first pattern of both LED’s should run in loop continuously, and when I click "Pattern2" button the second pattern should run in loop continuously until I click any other button.
My Code is:
#include <ESP8266WiFi.h>const char* ssid = "MY_SSID";const char* password = "MY_SSID_PASSWORD";WiFiServer server(80);#define LED1 D3#define LED2 D4void setup() { pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); Serial.begin(115200); Serial.print("Connecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("NodeMCU is connected to WiFi"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); server.begin(); delay(3000);}void loop() { WiFiClient client; client = server.available(); if (client == 1) { String request = client.readStringUntil('\n'); client.flush(); Serial.println(request); if (request.indexOf("pattern01") != -1) { pattern1();} // This Pattern I want to run continuously until I click any other button on web page if (request.indexOf("pattern02") != -1) { pattern2();} // This Pattern I want to run continuously until I click any other button on web page client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(""); client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.println("<head>"); client.println("<title> Led Pattern </title>"); client.println("</head>"); client.println("<body align= \"center\" >"); client.println("<h3> <font size = \"20\" face = \"Verdana\" > Led Pattern Continue Loop Control </font> </h3> "); client.println("<p> <a href=\"/pattern01\"> <button style=\"height:60px; background-color: #195B6A; width:200px; cursor: pointer\"><b> Pattern 1 </b></button> <a> </font></p> "); client.println("<p> <a href=\"/pattern02\"> <button style=\"height:60px; background-color: #195B6A; width:200px; cursor: pointer\"><b> Pattern 2 </b></button> <a> </font></p> "); client.println("</body>"); client.println("</html>"); Serial.println("Client disonnected"); Serial.println("------------------"); Serial.println(" "); }}void pattern1(){ digitalWrite(LED1,HIGH); delay(50); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); delay(50); digitalWrite(LED1,LOW); delay(50); digitalWrite(LED1,HIGH); delay(50); digitalWrite(LED1,LOW); delay(50); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); delay(50); digitalWrite(LED1,LOW); delay(50); digitalWrite(LED1,HIGH); delay(50); digitalWrite(LED1,LOW); delay(50); digitalWrite(LED1,HIGH); delay(50); digitalWrite(LED1,LOW); delay(50); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED2,LOW); delay(50); // I want to start the loop "Pattern 1" again}void pattern2(){ digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50); digitalWrite(LED1,HIGH); digitalWrite(LED2,HIGH); delay(50); digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); delay(50);}
Subhendu Mondal said:using esp8266
You're in the wrong forum - that's nothing to do with ARM!
Try: https://www.esp8266.com/
or: https://bbs.espressif.com/