请使用Nodemcu上的两个或多个led控件的代码来帮助您,我有一个LED控件的代码,并且无法使其在两个或多个上工作。我在Martyn Currey网站上找到了这个惊人的代码,并写了给他,但没有得到答案,所以我请您帮忙。我有一个很棒的代码,可让我控制一个来自nodemcu上的网络的LED,我想控制两个分离的LED,请您帮忙。这是代码:
#include <ESP8266WiFi.h>
const char WiFiPassword[] = "wifi";
const char AP_NameChar[] = "wifi" ;
WiFiServer server(80);
String header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
String html_1 = "<!DOCTYPE html><html><head><meta name='viewport' content='width=device-width, initial-scale=1.0'/><meta charset='utf-8'><style>body {font-size:140%;} #main {display: table; margin: auto; padding: 0 10px 0 10px; } h2,{text-align:center; } .button { padding:10px 10px 10px 10px; width:100%; background-color: #4CAF50; font-size: 120%;}</style><title>LED Control</title></head><body><div id='main'><h2>LED Control</h2>";
String html_2 = "";
String html_4 = "</div></body></html>";
String request = "";
int LED_Pin = D7;
int LED_Pin2 = D8;
void setup()
{
pinMode(LED_Pin, OUTPUT);
pinMode(LED_Pin2, OUTPUT);
boolean conn = WiFi.softAP(AP_NameChar, WiFiPassword);
server.begin();
} // void setup()
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) { return; }
// Read the first line of the request
request = client.readStringUntil('\r');
if ( request.indexOf("LEDON") > 0 ) { digitalWrite(LED_Pin, HIGH); }
else if ( request.indexOf("LEDOFF") > 0 ) { digitalWrite(LED_Pin, LOW); }
// Get the LED pin status and create the LED status message
if (digitalRead(LED_Pin) == HIGH)
{
// the LED is on so the button needs to say turn it off
html_2 = "<form id='F1' action='LEDOFF'><input class='button' type='submit' value='Turn of the LED' ></form><br>";
}
else
{
// the LED is off so the button needs to say turn it on
html_2 = "<form id='F1' action='LEDON'><input class='button' type='submit' value='Turn on the LED' ></form><br>";
}
client.flush();
client.print( header );
client.print( html_1 );
client.print( html_2 );
client.print( html_4);
delay(5);
// The client will actually be disconnected when the function returns and 'client' object is detroyed
} // void loop()
请帮助。