Run a modified servo in a webserver using Ethernet shield

Good day!
I'm planning to make a modified servo run continuously by controlling it in a webserver. My reference is this site Arduino - Webserver with an Arduino + Ethernet Shield | Random Nerd Tutorials but he only uses a normal servo which only rotates in 180. My problem is what codes that I will going to change if I would like to run a servo continuously. Here is the code

/*
Created by Rui Santos
Visit: http://randomnerdtutorials.com for more arduino projects

Arduino with Ethernet Shield
*/

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
int led = 4;
Servo microservo;
int pos = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 178 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(led, OUTPUT);
microservo.attach(7);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging

client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println("");
client.println("");
client.println("");
client.println("");
client.println("Random Nerd Tutorials Project");
client.println("");
client.println("");
client.println("

Random Nerd Tutorials Project

");
client.println("
");
client.println("
");
client.println("

Arduino with Ethernet Shield

");
client.println("
");
client.println("<a href="/?button1on"">Turn On LED");
client.println("<a href="/?button1off"">Turn Off LED
");
client.println("
");
client.println("
");
client.println("<a href="/?button2on"">Rotate Left");
client.println("<a href="/?button2off"">Rotate Right
");
client.println("

Created by Rui Santos. Visit http://randomnerdtutorials.com for more projects!

");
client.println("
");
client.println("");
client.println("");

delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(led, HIGH);
}
if (readString.indexOf("?button1off") >0){
digitalWrite(led, LOW);
}
if (readString.indexOf("?button2on") >0){
for(pos = 0; pos < 180; pos += 3) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
microservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (readString.indexOf("?button2off") >0){
for(pos = 180; pos>=1; pos-=3) // goes from 180 degrees to 0 degrees
{
microservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
//clearing string for next read
readString="";

}
}
}
}
}

Well first you need to understand how a continuous servo works, then you'll be able to answer your own question. Operating a continuous servo is no different from a code point of view from a normal servo: but you do need to know how it works so you can decide what commands to send.

A continuous servo only has direction and speed, it has no concept to position. So the position value in a line of your code like this one....

microservo.write(pos);

.... controls both the speed and direction but not position anymore.

A value of pos of 90 degrees will be stationary, <90 will be in one direction and closer to 0 the faster, and >90 is the other direction, faster towards 180.

Thank you for the quick response! Sorry for this, I'm newbie in this kind of work and hoping to learn more. Based on what you said

microservo.write(90); //no movement
microservo.write(0); //full-speed in one direction
microservo.write(180); //full-speed in the other direction

Are this lines

for(pos = 0; pos < 180; pos += 3)
for(pos = 180; pos>=1; pos-=3)

are not useful anymore?

Well they will cause movement of the servo of speed and direction between those limits- speed up slow down kind of thing; it depends what you want to do.... if you just want the servo to rotate at a fixed speed in one direction then just one write command in there.

Thank you very much for your time. I will update if it will work.

Did you modify your servo for continious rotation your self, or purchase one already modified? Continious rotation servos generally need to have the pot adjusted (if a pot is retained instead of using resistors) for no movement when a neutral command like 1500us is given. Below is some servo test code for use with the serial monitor that you can use to test the neutral no movement command value and determine the command range for variable speed/direction.

// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type a character (s to increase or a 
// to decrease) and enter to change servo position 
// (two hands required, one for letter entry and one for enter key)
// use strings like 90x or 1500x for new servo position 
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include<Servo.h>
String readString;
Servo myservo;
int pos=1500; //~neutral value for continous rotation servo
//int pos=90;

void setup()
{
  myservo.attach(7, 400, 2600); //servo control pin, and range if desired
  Serial.begin(9600);
  Serial.println("serial servo incremental test code");
  Serial.println("type a character (s to increase or a to decrease)");
  Serial.println("and enter to change servo position");
  Serial.println("use strings like 90x or 1500x for new servo position");
  Serial.println();
}

void loop()
{
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }
  if (readString.length() >0) {
    if(readString.indexOf('x') >0) { 
      pos = readString.toInt();
    }

    if(readString =="a"){
      (pos=pos-1); //use larger numbers for larger increments
      if(pos<0) (pos=0); //prevent negative number
    }
    if (readString =="s"){
      (pos=pos+1);
    }

    if(pos >= 400) //determine servo write method
    {
      Serial.println(pos);
      myservo.writeMicroseconds(pos);
    }
    else
    {   
      Serial.println(pos);
      myservo.write(pos); 
    }
  }
  readString=""; //empty for next input
}

I modified a servo by myself and already discard the potentiometer and replaced a 2 resistors. I have a question, why do you use the 1500 initial position for no movements instead of 90?

I have a question, why do you use the 1500 initial position for no movements instead of 90?

If you try the code I posted with both the deg and us, you will see you can get much better control of the servo with us. If you used resistors, your neutral no movement command position may not be 90 deg. or 1500us.

Then what is the neutral position for using resistors?

Then what is the neutral position for using resistors?

You will need to test various values to find the neutral position.