제가 기숙사랑 학교 왔다갔다 하다가 아두이노를 기숙사에 놓고왔거든요.
그래서 소스코드는 짰는데 시험을 못하고 있습니다. 제 의도대로 되는지 확인 부탁드립니다.
D1mini Wifi를 이용하여 웹페이지를 만들고 웹페이지 안에 버튼으로 서보모터를 제어하는 것인데요.
소스코드 보고 잘 되는지 봐주세요.
#include <ESP8266WiFi.h>
#include <Servo.h>
Servo servo;
const char* ssid = "i2r";
const char* password = "00000000";
const int Pinservo =0;
const int bt1 = 2;
const int bt2 = 3;
WiFiServer server(80);
void setup() {
Serial.begin(9600);
servo.attach(7);
pinMode(bt1, INPUT);
pinMode(bt2, INPUT);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
Serial.println(WiFi.localIP());
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("new client");
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
if (req.indexOf("/?bt1=Push") > 0) {
Serial.println(digitalRead(bt1));
if(digitalRead(bt1) == HIGH && pinservo <=180){
pinservo++;
servo.write(pinservo);
delay(5);
}
}
else if (req.indexOf("/?bt2=Push") > 0) {
Serial.println(digitalRead(bt2));
if(digitalRead(bt2) == HIGH && pinservo >=0){
pinservo--;
servo.write(pinservo);
delay(5);
}
}
client.println("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n");
client.println("<body>");
client.println("<br />");
//client.println(F(" <form method=\"post\">"));
client.println(F(" <form method=\"get\">"));
if(!digitalRead(bt1)) {
client.println(F(" <input type=\"hidden\" name=\"bt1\" value=\"Push\">"));
client.println(F(" bt1 <input type=\"button\" name=\"button1\" value=\"Push\" onclick=\"submit();\" >"));
}
if(!digitalRead(bt2)){
client.println(F(" <input type=\"hidden\" name=\"bt2\" value=\"Push\">"));
client.println(F(" bt2 <input type=\"button\" name=\"button1\" value=\"Push\" onclick=\"submit();\">"));
}
client.println(F(" </form>"));
client.println("</body>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
}
https://create.arduino.cc/editor