如何从 HTM 中获取输入整数? - Arduino / NodeMCU ESP32

问题描述

嗨,我目前正在做伺服 NodeMCU 控制。我的计划是创建一个可以输入的输入框,然后我输入的任何数字都将用作使用 Webserver 或 194.168.4.1 左右的伺服角度。 (例如:我输入 90,伺服角将是 90)问题我不知道如何得到它。这是代码

#include<Servo.h>
Servo ServoPin;
int angle = 0;
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>

#define ServoPin 34;   // Set the GPIO pin where you connected your test LED or comment this line out if your dev board has a built-in LED
// Set these to your desired credentials.
const char *ssid = "XXXXXX";
const char *password = "XXXXXX";

WiFiServer server(80);


void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println("Configuring access point...");
  pinMode(ServoPin,OUTPUT);
  // You can remove the password parameter if you want the AP to be open.
  WiFi.softAP(ssid,password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin();

  Serial.println("Server started");
}

void loop() {
  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,Serial.println("New Client.");           // print a message out 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
        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();

            // the content of the HTTP response follows the header:
            client.print("<!DOCTYPE html>");
            client.print("<html>");
            client.print("<body>");
            client.print("<p>Change the text of the text field,and then click the button below.</p>"); //
            client.print("INPUT NUMBER: <input type='number' id='servo'>"); //in this area,I WILL TYPE number 0-255.
            client.print("<button type='button' '>Go</button>");
            ServoPin.attach(number);  //the area where i will assign the servo to the angle i type.
          
            // 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
        }
      }
    }
    
    // close the connection:
    client.stop();
    Serial.println("Client disconnected.");
  }
}

正如你在 client.print"INPUT NUMBER.... 中看到的那样,那是我的代码将设计输入框的地方。问题是它在 " " 或双引号内。我想知道我应该怎么做才能获得“数字”输入然后在 ServoPin.attach(number) 上使用它;

我是 HTML 的初学者(实际上为零),因为我还没有这方面的知识。这段代码主要取自互联网 w3school 网站,然后我将其修改为伺服控制。所以我真的希望有人能告诉我怎么做....

板:Node32 实际开发板:NodeMCU ESP 32

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)