How to fix this servo code

I am trying to finalize this code for three servos. I am using code from the “sweep” example to do it. It is supposed to run one servo twice and two other servos once. The problem is that I do not know how to set up all my variables and integers and names. I don’t know what is needed for multiple servos or how to “attach” multiple servos and control them.

Right now I am just trying to iron out the first servo so the code for the other two is blank and empty.

so, what is the grammar format and setup for multiple servo control?

#include <Servo.h> 

//int motorPinA = 10;
int ledPin = 3;
int repetitions = 0;
int iterations = 0;
//int motorPinB = 5;
//int motorPinC = 8;




//int servoA;
//int servoB;
//int servoC;

Servo servoA;
Servo servoB;
Servo servoC;


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



 
//Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int servoPosA = 0;    // variable to store the servo position, all sevo positions start at zero, as they should.
int servoPosB = 0;
int servoPosC = 0;
 













void setup()
{
  int ledPin;
  //int motorPin;
  //pinMode (motorPinA, OUTPUT);
  pinMode(ledPin, OUTPUT);
  int repetitions;
  int iterations;
  int myservo;
  
  //int motorPinB;
  //pinMode(motorPinB, OUTPUT);
  myservo.attach(5);  // attaches the servo (A) on pin 5 to the servo object 
  myservo.attach(8);  // a servo (B) is attached to pin 8
  myservo.attach(9);  // a servo (C) is attached to pin 9
}












void loop()
{
 if(iterations >= 2)
 {
      //analogWrite(motorPinA, LOW);
      analogWrite(ledPin, 0);
      //Servo A needs to go to zero, 0, closed, and stay there when   
 }
else
{
  for(int repetitions=0;repetitions<2;repetitions++)
  {
    delay(2000);
    analogWrite(ledPin, 1000);
    delay(2000);
    //Servo A needs to go to 90 degrees, open
    
    
    
    
          for(servoPosa = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees 
       {                                  // in steps of 1 degree 
         myservo.write(servoPosA);              // tell servo to go to position in variable 'pos' 
         delay(15);                       // waits 15ms for the servo to reach the position 
       } 
       for(servoPosA = 90; servoPosA>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
       {                                
         myservo.write(servoPosA);              // tell servo to go to position in variable 'pos' 
         delay(15); 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    //analogWrite(motorPinA, 70);
    delay (3000);
    
    analogWrite(ledPin, 0);
    //servo A needs to be at 0, closed
    
    
    
    
    
    
    
    //analogWrite(motorPinA, LOW);
    iterations++;           // # value of iterations is counted up by one.
    
    
    if(iterations % 2 ==1) // this will devide iteraions by two and every time there is a remainder of one (AKA each time there is an odd number, AKA every other iteration, an (#.5 number) because that remainder 1 gets divided by two to make a .5*2 = 1, AKA once per day!)
                          // This means that we can give her the twice-a-day-pills and then give her the once a day pills! We just need to adjust the timeing to match a 24-hour day!
   {
    delay(10); //debounce the system
    //make servos B and C run for once a day
    
    
    
    
    
    
    
    
    //analogWrite(motorPinB, 80);
    //delay(300);               Motor A and Motor B may have a need for different speeds, depending on the size and shape of each of the various pills we dispense. Use this code if this is necessary
    //analogWrite(motorPinC, 80);
    delay(300); //how long the motors need to run to spit out exactly one pill of each
   }
  else
  {
delay(10); //debounce the system

// leave servos B and C stay off on the even(second) run of servo A, meaning that A gives twice a day while B and C give once a day.









//analogWrite(motorPinB, LOW); //this is a pill that is given only once a day, motor left off
//analogWrite(motorPinC, LOW); //this is a pill that is given only once a day, motor left off
  } 
  } 
 }
}

I am getting lots of errors about the setup, non class-type int and etcetera.

IEP_final_project_iteration_4_06_big_theory_application_1:17: error: expected initializer before 'void'
IEP_final_project_iteration_4_06_big_theory_application_1:49: error: expected initializer before 'void'
IEP_final_project_iteration_4_06_big_theory_application_1.ino: In function 'void loop()':
IEP_final_project_iteration_4_06_big_theory_application_1:97: error: 'servoPosa' was not declared in this scope
IEP_final_project_iteration_4_06_big_theory_application_1:99: error: 'myservo' was not declared in this scope
IEP_final_project_iteration_4_06_big_theory_application_1:102: error: 'pos' was not declared in this scope
IEP_final_project_iteration_4_06_big_theory_application_1:104: error: 'myservo' was not declared in this scope
IEP_final_project_iteration_4_06_big_theory_application_1:174: error: expected `}' at end of input

I don’t know what some of these mean

I am also fixing the cases of capitalization and etcetera, so ignore those But I don't know what grammar and format are required to operate three servos

First error is on this line:

  myservo.attach(5);  // attaches the servo (A) on pin 5 to the servo object

myservo isn't declared. Replace it here with servoA. Two similar changes on subsequent lines

Ok

Now I have this code:
It says that I need a curly brace but which one.
Otherwise, what is your opinion? What would you suggest? Anything at all.

#include <Servo.h> 

//int motorPinA = 10;
int ledPin = 3;
int repetitions = 0;
int iterations = 0;
//int motorPinB = 5;
//int motorPinC = 8;




//int servoA;
//int servoB;
//int servoC;

Servo servoA;
Servo servoB;
Servo servoC;


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



 
//Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int servoPosA = 0;    // variable to store the servo position, all sevo positions start at zero, as they should.
int servoPosB = 0;
int servoPosC = 0;
 













void setup()
{
  int ledPin;
  //int motorPin;
  //pinMode (motorPinA, OUTPUT);
  pinMode(ledPin, OUTPUT);
  int repetitions;
  int iterations;
  int myservo;
  
  
  //int motorPinB;
  //pinMode(motorPinB, OUTPUT);
  servoA.attach(5);  // attaches the servo (A) on pin 5 to the servo object 
  servoB.attach(8);  // a servo (B) is attached to pin 8
  servoC.attach(9);  // a servo (C) is attached to pin 9
}












void loop()
{
 if(iterations >= 2)
 {
      //analogWrite(motorPinA, LOW);
      analogWrite(ledPin, 0);
      //Servo A needs to go to zero, 0, closed, and stay there when   
 }
else
{
  for(int repetitions=0;repetitions<2;repetitions++)
  {
    delay(2000);
    analogWrite(ledPin, 1000);
    delay(2000);
    //Servo A needs to go to 90 degrees, open
    
    
    
    
          for(servoPosA = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees 
       {                                  // in steps of 1 degree 
         servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
         delay(15);                       // waits 15ms for the servo to reach the position 
       } 
       for(servoPosA = 90; servoPosA>=1; servoPosA-=1)     // goes from 180 degrees to 0 degrees 
       {                                
         servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
         delay(15); 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    //analogWrite(motorPinA, 70);
    delay (3000);
    
    analogWrite(ledPin, 0);
    //servo A needs to be at 0, closed
    
    
    
    
    
    
    
    //analogWrite(motorPinA, LOW);
    iterations++;           // # value of iterations is counted up by one.
    
    
    if(iterations % 2 ==1) // this will devide iteraions by two and every time there is a remainder of one (AKA each time there is an odd number, AKA every other iteration, an (#.5 number) because that remainder 1 gets divided by two to make a .5*2 = 1, AKA once per day!)
                          // This means that we can give her the twice-a-day-pills and then give her the once a day pills! We just need to adjust the timeing to match a 24-hour day!
   {
    delay(10); //debounce the system
    //make servos B and C run for once a day
    
    
    
    
    
    
    
    
    //analogWrite(motorPinB, 80);
    //delay(300);               Motor A and Motor B may have a need for different speeds, depending on the size and shape of each of the various pills we dispense. Use this code if this is necessary
    //analogWrite(motorPinC, 80);
    delay(300); //how long the motors need to run to spit out exactly one pill of each
   }
  else
  {
delay(10); //debounce the system

// leave servos B and C stay off on the even(second) run of servo A, meaning that A gives twice a day while B and C give once a day.









//analogWrite(motorPinB, LOW); //this is a pill that is given only once a day, motor left off
//analogWrite(motorPinC, LOW); //this is a pill that is given only once a day, motor left off
  } 
  } 
 }
}

Have you

noticed

that. when. things wander All. Over

The page, they're really hard to read? The IDE has a useful auto format tool. Please find and use it.

Yes

It

Helps me

visually distinguish

where code needs to be

XD

Anyways, there is a left curly brace somewhere that needs it's pair or to be deleted

Every opening brace needs a corresponding closing brace. Your loop() function starts with an opening brace but where does it end ? Position the cursor after any brace or bracket and the corresponding matching one will be indicated if it is present.

If you got rid of most of the blank lines in your program it would help as would Auto formatting it (if it worked - try it and see)

    analogWrite(ledPin, 1000);
    delay(2000);
    //Servo A needs to go to 90 degrees, open
    
    
    
    
          for(servoPosA = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees 
       {                                  // in steps of 1 degree 
         servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
         delay(15);                       // waits 15ms for the servo to reach the position 
       }

Really?

Those of us who have been at this a little longer just get eye-ache, or queasy

Autoformat wants me to close that curly brace before it will format the code.

Clever, clever auto-format.

OK, now it is compiled and formatted.
I just would like any opinion or advice: do you think that this will work?
How could it be made to work better?

#include <Servo.h> 

//int motorPinA = 10;
int ledPin = 3;
int repetitions = 0;
int iterations = 0;
//int motorPinB = 5;
//int motorPinC = 8;




//int servoA;
//int servoB;
//int servoC;

Servo servoA;
Servo servoB;
Servo servoC;


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




//Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created 

int servoPosA = 0;    // variable to store the servo position, all sevo positions start at zero, as they should.
int servoPosB = 0;
int servoPosC = 0;














void setup()
{
  int ledPin;
  //int motorPin;
  //pinMode (motorPinA, OUTPUT);
  pinMode(ledPin, OUTPUT);
  int repetitions;
  int iterations;
  int myservo;


  //int motorPinB;
  //pinMode(motorPinB, OUTPUT);
  servoA.attach(5);  // attaches the servo (A) on pin 5 to the servo object 
  servoB.attach(8);  // a servo (B) is attached to pin 8
  servoC.attach(9);  // a servo (C) is attached to pin 9
}












void loop()
{
  if(iterations >= 2)
  {
    //analogWrite(motorPinA, LOW);
    analogWrite(ledPin, 0);
    //Servo A needs to go to zero, 0, closed, and stay there when   
  }
  else
  {
    for(int repetitions=0;repetitions<2;repetitions++)
    {
      delay(2000);
      analogWrite(ledPin, 1000);
      delay(2000);
      //Servo A needs to go to 90 degrees, open




      for(servoPosA = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees 
      {                                  // in steps of 1 degree 
        servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
        delay(15);                       // waits 15ms for the servo to reach the position 
      } 
      for(servoPosA = 90; servoPosA>=1; servoPosA-=1)     // goes from 180 degrees to 0 degrees 
      {                                
        servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
        delay(15); 















        //analogWrite(motorPinA, 70);
        delay (3000);

        analogWrite(ledPin, 0);
        //servo A needs to be at 0, closed







        //analogWrite(motorPinA, LOW);
        iterations++;           // # value of iterations is counted up by one.


        if(iterations % 2 ==1) // this will devide iteraions by two and every time there is a remainder of one (AKA each time there is an odd number, AKA every other iteration, an (#.5 number) because that remainder 1 gets divided by two to make a .5*2 = 1, AKA once per day!)
          // This means that we can give her the twice-a-day-pills and then give her the once a day pills! We just need to adjust the timeing to match a 24-hour day!
        {
          delay(10); //debounce the system
          //make servos B and C run for once a day








          //analogWrite(motorPinB, 80);
          //delay(300);               Motor A and Motor B may have a need for different speeds, depending on the size and shape of each of the various pills we dispense. Use this code if this is necessary
          //analogWrite(motorPinC, 80);
          delay(300); //how long the motors need to run to spit out exactly one pill of each
        }
        else
        {
          delay(10); //debounce the system

          // leave servos B and C stay off on the even(second) run of servo A, meaning that A gives twice a day while B and C give once a day.









          //analogWrite(motorPinB, LOW); //this is a pill that is given only once a day, motor left off
          //analogWrite(motorPinC, LOW); //this is a pill that is given only once a day, motor left off
        } 
      } 
    }
  }
}

Reading your code is hard work because of all the blank lines so I gave up after a while, but I did notice this line analogWrite(ledPin, 1000);What is the maximum value that can usefully be used with analogWrite() ?

From the reference page

Syntax

analogWrite(pin, value) Parameters

pin: the pin to write to. value: the duty cycle: between 0 (always off) and 255 (always on).

eah, it's under Tools, but it doesn't do anything

Please, step away from the keyboard, and no-one will get hurt.

Seems some people have a lot idle time.

#include <Servo.h> 

//int motorPinA = 10;
int ledPin = 3;
int repetitions = 0;
int iterations = 0;
//int motorPinB = 5;
//int motorPinC = 8;

//int servoA;
//int servoB;
//int servoC;

Servo servoA;
Servo servoB;
Servo servoC;

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

//Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created 

int servoPosA = 0;    // variable to store the servo position, all sevo positions start at zero, as they should.
int servoPosB = 0;
int servoPosC = 0;

void setup()
{
  int ledPin;
  //int motorPin;
  //pinMode (motorPinA, OUTPUT);
  pinMode(ledPin, OUTPUT);
  int repetitions;
  int iterations;
  int myservo;

  //int motorPinB;
  //pinMode(motorPinB, OUTPUT);
  servoA.attach(5);  // attaches the servo (A) on pin 5 to the servo object 
  servoB.attach(8);  // a servo (B) is attached to pin 8
  servoC.attach(9);  // a servo (C) is attached to pin 9
}

void loop()
{
  if(iterations >= 2)
  {
    //analogWrite(motorPinA, LOW);
    analogWrite(ledPin, 0);
    //Servo A needs to go to zero, 0, closed, and stay there when   
  }
  else
  {
    for(int repetitions=0;repetitions<2;repetitions++)
    {
      delay(2000);
      analogWrite(ledPin, 1000);
      delay(2000);
      //Servo A needs to go to 90 degrees, open

      for(servoPosA = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees 
      {                                  // in steps of 1 degree 
        servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
        delay(15);                       // waits 15ms for the servo to reach the position 
      } 
      for(servoPosA = 90; servoPosA>=1; servoPosA-=1)     // goes from 180 degrees to 0 degrees 
      {                                
        servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
        delay(15); 

        //analogWrite(motorPinA, 70);
        delay (3000);

        analogWrite(ledPin, 0);
        //servo A needs to be at 0, closed

        //analogWrite(motorPinA, LOW);
        iterations++;           // # value of iterations is counted up by one.

        if(iterations % 2 ==1) // this will devide iteraions by two and every time there is a remainder of one (AKA each time there is an odd number, AKA every other iteration, an (#.5 number) because that remainder 1 gets divided by two to make a .5*2 = 1, AKA once per day!)
          // This means that we can give her the twice-a-day-pills and then give her the once a day pills! We just need to adjust the timeing to match a 24-hour day!
        {
          delay(10); //debounce the system
          //make servos B and C run for once a day

          //analogWrite(motorPinB, 80);
          //delay(300);               Motor A and Motor B may have a need for different speeds, depending on the size and shape of each of the various pills we dispense. Use this code if this is necessary
          //analogWrite(motorPinC, 80);
          delay(300); //how long the motors need to run to spit out exactly one pill of each
        }
        else
        {
          delay(10); //debounce the system

          // leave servos B and C stay off on the even(second) run of servo A, meaning that A gives twice a day while B and C give once a day.
          //analogWrite(motorPinB, LOW); //this is a pill that is given only once a day, motor left off
          //analogWrite(motorPinC, LOW); //this is a pill that is given only once a day, motor left off
        } 
      } 
    }
  }
}
for(servoPosA = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees

Maybe, with 1:2.something gearing.

Analog write technically only goes up to 255, but in practice it works fine in giving power to LED's up to a value of 1023.

The spaces are to help me see where I will place code in the future.

Analog write technically only goes up to 255,

Unless you're on a Due, there's no "technically" about it, and the sooner you convince yourself of that, the happier we'll all be. If you want a sawtooth, keep using 0..1023, otherwise use 0..255.

In theory, analogWrite can only be used to give up to 255, but in practice you may use it to light LED's that use values up to 1023.

The spaces are temporary so that I can see visually where code will go in the future.

It is formatted. The spaces stay.