Arduino - encender led con input type text

 
Vista:
sin imagen de perfil

encender led con input type text

Publicado por joran (5 intervenciones) el 07/06/2019 00:39:49
Saludos tengo un ejercicio el cual deseo saber como poder encender un led con escribir en un input type text, si escribo 1 encienda y si escribo 0 apague, deseo saber como enviar resultados a la placa, me a costado entender el html y modificarlo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
 
/* Your WiFi Soft Access Point settings */
const char* ssid = "NODEMCU";   //this will be the network name
const char* password = "12345678";  //this will be the network password
int stateLED = LOW;
 
ESP8266WebServer server(80);
 
const String HtmlHtml = "<html><head>"
    "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /></head>";
const String HtmlHtmlClose = "</html>";
const String HtmlTitle = "<h1>ESP8266 AP WebServer by Vitali M.</h1><br/>\n";
const String HtmlLedStateLow = "<big>LED is now <b>OFF</b></big><br/>\n";
const String HtmlLedStateHigh = "<big>LED is now <b>ON</b></big><br/>\n";
const String HtmlButtons =
    "<a href=\"LEDOn\"><button style=\"display: block; width: 100%;\">ON</button></a><br/>"
    "<a href=\"LEDOff\"><button style=\"display: block; width: 100%;\">OFF</button></a><br/>";
 
 
AQUI DESEARIA ENCENDER LED CON ESCRITURA EN ESTE CASO 1 Ó 0
<input type="text"> <input type="submit">
 
 
 
 
void handleRoot() {
    response();
}
 
void handleLedOn() {
  stateLED = HIGH;
  digitalWrite(13, stateLED);
  response();
}
 
void handleLedOff() {
  stateLED = LOW;
  digitalWrite(13, stateLED);
  response();
}
 
void response(){
  String htmlRes = HtmlHtml + HtmlTitle;
  if(stateLED == LOW){
    htmlRes += HtmlLedStateLow;
  }else{
    htmlRes += HtmlLedStateHigh;
  }
 
  htmlRes += HtmlButtons;
  htmlRes += HtmlHtmlClose;
 
  server.send(200, "text/html", htmlRes);
}
 
void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.println();
  Serial.print("Configuring WiFi access point...");
 
  /* You can remove the password parameter if you want the AP to be open. */
  boolean result = WiFi.softAP(ssid, password);
  if(result==true) {
    IPAddress myIP = WiFi.softAPIP();
 
    Serial.println("done!");
    Serial.println("");
    Serial.print("WiFi network name: ");
    Serial.println(ssid);
    Serial.print("WiFi network password: ");
    Serial.println(password);
    Serial.print("Host IP Address: ");
    Serial.println(myIP);
    Serial.println("");
 
 
    server.on("/", handleRoot);
    server.on("/1", handleLedOn);
    server.on("/0", handleLedOff);
    server.begin();
    Serial.println("HTTP server beginned");
    pinMode(13, OUTPUT);
    digitalWrite(13, stateLED);
 
  } else {
    Serial.println("error! Something went wrong...");
  }
}
 
void loop() {
    server.handleClient();
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder