Last active
January 9, 2023 23:35
-
-
Save igrr/9ef4d5c74355503e3b1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
#include <ESP8266WiFi.h> | |
#include <ESP8266WebServer.h> | |
const char* ssid = "your-ssid"; | |
const char* pass = "your-password"; | |
ESP8266WebServer server(80); | |
Servo myservo; | |
void setup(void){ | |
Serial.begin(115200); | |
Serial.println(""); | |
WiFi.begin(ssid, pass); | |
// Wait for connection | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.print("Connected to "); | |
Serial.println(ssid); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); | |
server.on("/", [](){ | |
server.send(200, "text/plain", "Open /servo?value=90 to control servo"); | |
}); | |
server.on("/servo", [](){ | |
String sval = server.arg("value"); | |
int ival = sval.toInt(); | |
Serial.print("Servo: "); | |
Serial.println(ival); | |
myservo.write(ival); | |
server.send(200, "text/plain", String(ival, DEC)); | |
}); | |
server.begin(); | |
Serial.println("HTTP server started"); | |
myservo.attach(D5); // Servo attached to D5 pin on NodeMCU board | |
myservo.write(0); | |
} | |
void loop(void){ | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jtheires you need to disinstall the Servo library, and use the one built-in the Arduino SDK for ESP8266.