Hi everyone!
First of all thanks for trying to help me out here, much appreciated.
Long story short, I created a webserver on my Wemos D1 mini and created 2 buttons start & stop
When pressed start the servo motor turns from 0 to 180 degrees and back from 180 to 0 degrees. Once.
Stop actually doesn't do anything yet.
So far this works.
-Now I want to figure out a way to loop the movement of the servo motor until I press stop.
I tried many times with do/while statements but it gets stuck in the loop, so the stop commando doesn't reach the server.
This is the code (from void loop()) to run it once. Can somebody help me trying to loop it until stop is pressed?
void loop() {
-
WiFiClient client = server.available();*
-
if (!client) {*
-
return;*
-
}*
-
Serial.println("new client");*
-
while(!client.available()){*
-
delay(1);*
-
}*
-
// Read the first line of the request*
-
String request = client.readStringUntil('\r');*
-
Serial.println(request);*
-
client.flush();*
// Match the request
if (request.indexOf("/start=1") != -1) {
client.println("Start
" );
myservo.attach(12);
for (int pos = 0; pos <= 180; pos += 180) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for (int pos = 180; pos >= 0; pos -= 180) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
delay(1000);
}
if (request.indexOf("/stop=1") != -1) {
myservo.detach(); // I believe this will work as stop command, let's assume it works.
}
-
// Return the response*
-
client.println("HTTP/1.1 200 OK");*
-
client.println("Content-Type: text/html");*
-
client.println("");*
-
client.println("");*
-
client.println("");*
-
client.println("
Test
*
"); -
client.println("*
"); -
client.println("<a href="/start=1"">Start Motor *
"); -
client.println("<a href="/stop=1"">Stop Motor *
"); -
client.println("");*
-
delay(1);*
-
Serial.println("Client disonnected");*
-
Serial.println("");*
}
Again many thanks for spening time trying to help me out here.
Cheers Viskuh!