continuous rotation servo

i am a 16 year old student just starting off coding and i’m having some issues trying to make my servos make just 1 360 turn. can anyone take a look at my code to see if there’s anything wrong or needed to work? (i only have the code for the servo in the first if statement, I’m waiting to add it to the rest once I find out what’s wrong)

#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;

int redLED1=8;
int redLED2=9;
int redLED3=10;
int redLED4=11;
int pushbutton1=4;
int pushbutton2=5;
int pushbutton3=6;
int pushbutton4=7;
int buttonstate=0;
int pos=0;

void setup() {
pinMode(pushbutton1, INPUT);
pinMode(pushbutton2, INPUT);
pinMode(pushbutton3, INPUT);
pinMode(pushbutton4, INPUT);
pinMode(redLED1, OUTPUT);
pinMode(redLED2, OUTPUT);
pinMode(redLED3, OUTPUT);
pinMode(redLED4, OUTPUT);
myservo1.attach(A1);
myservo2.attach(A2);
myservo3.attach(A3);
myservo4.attach(A4);
myservo1.write(0);
myservo2.write(0);
myservo3.write(0);
myservo4.write(0);
}

void loop() {
int sensorVal1 = digitalRead(pushbutton1);
int sensorVal2 = digitalRead(pushbutton2);
int sensorVal3 = digitalRead(pushbutton3);
int sensorVal4 = digitalRead(pushbutton4);

Serial.println(sensorVal1);

if (sensorVal1 == HIGH) {
digitalWrite(redLED1, HIGH);
delay(1000);
digitalWrite(redLED1, LOW);
myservo1.writeMicroseconds(700);

} else {
digitalWrite(redLED1, LOW);
Serial.println(sensorVal2);

if (sensorVal2 == HIGH){
digitalWrite(redLED2, HIGH);
delay(1000);
digitalWrite(redLED2, LOW);

} else {

digitalWrite(redLED2, LOW);

Serial.println(sensorVal3);

if (sensorVal3 == HIGH){
digitalWrite(redLED3, HIGH);
delay(1000);
digitalWrite(redLED3, LOW);

} else {

digitalWrite(redLED3, LOW);
Serial.println(sensorVal4);

if (sensorVal4 == HIGH){
digitalWrite(redLED4, HIGH);
delay(1000);
digitalWrite(redLED4, LOW);

} else {

digitalWrite(redLED4, LOW);

}
}
}
}
}

A continuous servo has the feedback pot disconnected so it has lost any ability to know its position. It becomes a gear motor with speed and direction control but not position control. Sending 700 will just make it spin in reverse at near full speed.

Read the how to use this forum-please read sticky to see how to, properly, post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

Like so:

#include <Servo.h>
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;

int redLED1 = 8;
int redLED2 = 9;
int redLED3 = 10;
int redLED4 = 11;
int pushbutton1 = 4;
int pushbutton2 = 5;
int pushbutton3 = 6;
int pushbutton4 = 7;
int buttonstate = 0;
int pos = 0;

void setup()
{
   pinMode(pushbutton1, INPUT);
   pinMode(pushbutton2, INPUT);
   pinMode(pushbutton3, INPUT);
   pinMode(pushbutton4, INPUT);
   pinMode(redLED1, OUTPUT);
   pinMode(redLED2, OUTPUT);
   pinMode(redLED3, OUTPUT);
   pinMode(redLED4, OUTPUT);
   myservo1.attach(A1);
   myservo2.attach(A2);
   myservo3.attach(A3);
   myservo4.attach(A4);
   myservo1.write(0);
   myservo2.write(0);
   myservo3.write(0);
   myservo4.write(0);
}


void loop()
{
   int sensorVal1 = digitalRead(pushbutton1);
   int sensorVal2 = digitalRead(pushbutton2);
   int sensorVal3 = digitalRead(pushbutton3);
   int sensorVal4 = digitalRead(pushbutton4);

   Serial.println(sensorVal1);

   if (sensorVal1 == HIGH)
   {
      digitalWrite(redLED1, HIGH);
      delay(1000);
      digitalWrite(redLED1, LOW);
      myservo1.writeMicroseconds(700);
   }
   else
   {
      digitalWrite(redLED1, LOW);
      Serial.println(sensorVal2);
      if (sensorVal2 == HIGH)
      {
         digitalWrite(redLED2, HIGH);
         delay(1000);
         digitalWrite(redLED2, LOW);
      }
      else
      {
         digitalWrite(redLED2, LOW);
         Serial.println(sensorVal3);
         if (sensorVal3 == HIGH)
         {
            digitalWrite(redLED3, HIGH);
            delay(1000);
            digitalWrite(redLED3, LOW);
         }
         else
         {
            digitalWrite(redLED3, LOW);
            Serial.println(sensorVal4);
            if (sensorVal4 == HIGH)
            {
               digitalWrite(redLED4, HIGH);
               delay(1000);
               digitalWrite(redLED4, LOW);
            }
            else
            {
               digitalWrite(redLED4, LOW);
            }
         }
      }
   }
}

How are your buttons wired? Your code would indicate that you have external pull-down resistors attached so I hope you do... The more common method of wiring a button is to connect one side to ground and the other side to your input pin and then declare that pin as 'INPUT_PULLUP' to enable the internal pull-up resistor. This configuration changes the sense of the button. When pushed, it is shorted to ground and reads LOW. When not pushed, it reads HIGH.

If you really need to turn a full 360 degrees perhaps you could use a sail winch servo which does have positional control, usually over about 6 full turns. Or else add an encoder to your geared motor (aka continuous “servo” which isn’t really a servo any more).

Or alternatively if you want to do 360, stop for a while, then another 360 and keep doing that perhaps a stepper motor would be better.

It really depends on what exactly your project, whatever it is, needs to achieve.

Steve

May I suggest a simple problem to solve… get the servos to stop movement and switch direction. You are not likely to get a servo to stop exactly at a position ever. if you know how long it takes a servo to do @ 0 => 360 rotation, I would use a for loop.
if a servo only serves a single process and is not relativity to the rest of the program. You should disregard its position as it will not effect the rest of the programs flow, otherwise use an encoder wheel to read its position in relationship to its last known position.

Try this:

/* Sweep
by BARRAGAN http://barraganstudio.com
This example code is in the public domain.

modified 8 Nov 2013
by Scott Fitzgerald

*/

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop() {
for (pos = 0; pos <= 180; pos += 1) { // 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(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}