Program DC encoder with servo

Hi everyone,
I'm bulding a robot which have 14 servo motors and 4 dc motors with encoder.
I've currently have a program of the servos, each line another servo is move into another position, all the code should run 1 time and not more, so it's not a program of servo preforming sweep again and again.

and I need to combine the robot movement using 2 dc motors at a time, so that's in the end the robot will move his wheels and his arms (Where the servos are) all together, without any glitches.
I have a power supply for of the motors, they are'nt powered from the arduino so power is not my problem.

this is an example of the servo program

#include <VarSpeedServo.h>


VarSpeedServo myservo1;
VarSpeedServo myservo2;

VarSpeedServo myservo3;
VarSpeedServo myservo4;

VarSpeedServo myservo5;
VarSpeedServo myservo6;

VarSpeedServo myservo7;
VarSpeedServo myservo8;
VarSpeedServo myservo9;
VarSpeedServo myservo10;
VarSpeedServo myservo11;
VarSpeedServo myservo12;
VarSpeedServo myservo13;
VarSpeedServo myservo14;

void setup() {
 
 
 
 myservo1.attach(22);
 myservo2.attach(23);
 myservo3.attach(26);
 myservo4.attach(27);
 myservo5.attach(34);
 myservo6.attach(35);
 myservo7.attach(38);
 myservo8.attach(39);
 myservo9.attach(42);
 myservo10.attach(43);
 myservo11.attach(46);
 myservo12.attach(47);
 myservo13.attach(52);
 myservo14.attach(53);
    
//********************************************  
   
   
   myservo1.write(180,120);             
   myservo5.write(90,120); 
   myservo2.write(170,120);
   myservo6.write(130,120);
   myservo3.write(180,120);             
   myservo7.write(0,120);    
   myservo4.write(30,120);        
   myservo8.write(100,120);
   myservo9.write(40,120);              
   myservo10.write(0,120);             
   myservo11.write(82,120);              
   myservo12.write(160,120);  

   delay(4000);

   myservo1.write(180,120);             
   myservo5.write(0,120); 
   myservo2.write(170,120);
   myservo6.write(25,120);
   myservo3.write(180,120);              
   myservo7.write(0,120);    
   myservo4.write(30,120);        
   myservo8.write(160,120);
   myservo9.write(40,120);              
   myservo10.write(0,120);             
   myservo11.write(82,120);              
   myservo12.write(160,120);      
   delay(2300);

    

  myservo3.write(100, 80);   
  myservo7.write(90, 80);

 delay(500);
//****

myservo2.write(80, 80);
myservo4.write(120, 80);     
myservo6.write(120, 80);
myservo8.write(80, 80);

delay (600);


//*********************************************  
             
   myservo2.write(170,140);
   myservo6.write(25,140);
   myservo3.write(180,140);             
   myservo7.write(0,140); 
   myservo4.write(30,140);   
   myservo8.write(160,140);


   delay(1000);
 
//****
  myservo3.write(100, 80);   
  myservo7.write(90, 80);

 delay(500);
//****

myservo2.write(80, 80);
myservo4.write(120, 80);    
myservo6.write(120, 80);
myservo8.write(80, 80);

delay (500);


//************************************************

//*************************************************


}

void loop() {
 // put your main code here, to run repeatedly:

}

and this is a short example of how my encoder program is:

byte pwm=11;
byte EN=8;
byte forward=13;
byte reverse=12;

volatile int encorderValue=0;

void setup(){

Serial.begin(9600);

attachInterrupt(digitalPinToInterrupt(21),count,FALLING); 
}

void loop(){
 
while(encorderValue<=10000){
********* setup the motor driver to drive CW **********
digitalWrite(EN,1);
digitalWrite(forward,1);
digitalWrite(reverse,0);
*******************************************************
analogWrite(pwm,100); //define motor speed

Serial.print("Encoder Value=");
Serial.println(encorderValue); //printing the encoder value
}

********* setup the motor driver to brake state *******
analogWrite(pwm,0); //set motor speed to zero

********************************************************

delay(100);
encorderValue=0;
}

void count(){
encorderValue++; 
}

So my question is how can I combined this 2 program? I already have the servo program, and I the dc motors to move in different times in my program, with different speeds and round (encouder values).

Thanks for the helpers!

You have to disable interrupts while you read the "encorder" value (should be "encoder") in loop().

VarSpeedServo myservo1;
VarSpeedServo myservo2;

VarSpeedServo myservo3;
VarSpeedServo myservo4;

VarSpeedServo myservo5;
VarSpeedServo myservo6;

VarSpeedServo myservo7;
VarSpeedServo myservo8;
VarSpeedServo myservo9;
VarSpeedServo myservo10;
VarSpeedServo myservo11;
VarSpeedServo myservo12;
VarSpeedServo myservo13;
VarSpeedServo myservo14;

Arrays! This code just screams for arrays. It also screams for better names. What the hell do these servos do?

Your two improperly posted programs do something. Your unposted attempt to combine them does something. You want the unposted program to do something. Presumably the something that the unposted code does is not the same as the something that you want the unposted code to do. But, what either of those two somethings is is a mystery as is the code itself.

The Pink Panther might be along soon to solve the mystery. Or not. (I'm not putting any money on the Pink Panther making an appearance or on the mystery being solved by the Pink Panther)

PaulS:

VarSpeedServo myservo1;

VarSpeedServo myservo2;

VarSpeedServo myservo3;
VarSpeedServo myservo4;

VarSpeedServo myservo5;
VarSpeedServo myservo6;

VarSpeedServo myservo7;
VarSpeedServo myservo8;
VarSpeedServo myservo9;
VarSpeedServo myservo10;
VarSpeedServo myservo11;
VarSpeedServo myservo12;
VarSpeedServo myservo13;
VarSpeedServo myservo14;



Arrays! This code just screams for arrays. It also screams for better names. What the hell do these servos do?

Your two improperly posted programs do something. Your unposted attempt to combine them does something. You want the unposted program to do something. Presumably the something that the unposted code does is not the same as the something that you want the unposted code to do. But, what either of those two somethings is is a mystery as is the code itself.

The Pink Panther might be along soon to solve the mystery. Or not. (I'm not putting any money on the Pink Panther making an appearance or on the mystery being solved by the Pink Panther)

Hi, thanks for your help.
I know It's seems stupid to ask for help for a code I didn't wrote yet, but if I had a drirection I would already dont it.
I really don't know what to do, that's why I'm asking you to guide me for how can I mange this issue.

I'm asking you to guide me for how can I mange this issue.

Re-read my previous reply. We do not know what your issue is.