need help in checking arduino codes

Hi everyone

i got 2 set of arduino codes to use to make the brushless rotors spin .
The first set of codes which can be found in the example (knob) can make it spin.
However, the second set of code cant make it spin, although there is no error. it is above the same as the first set but added with
some other codes to interface with gyro sensors. can anyone help me solve the 2nd set of code ?

The second set of codes look something like this :

Servo myservo1;
Servo myservo2;

int potpin =0;
int gyropin = 1;
int joypin= 2;

int levelpin= 3;

int val1;
int val2;
int val3;
int val4;

int val5;//variable to read the main rotor gyro

int sum1;
int sum2;

void setup()
{
myservo1.attach(9);//control tail motor through pin 9
myservo2.attach(10);//control main rotor through pin 10
}

void loop()
{
val1=analogRead(potpin);
//(value between 0 and 1023) - read the value of the potentiometer

val1= map(val1,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo

val2=analogRead(gyropin);
//(value between 0 and 1023)- to read the value of the potentiometer

val2=map(val2,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo

val3=analogRead(joypin);
//(value between 0 and 1023)- to read the value of the potentiometer

val3=map(val3,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo

val5 = analogRead(levelpin);
// read the potentiometer(value between 0 and 1023)

val5 = map(val5,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo

val4 = 1500 - val3;
sum1 = (0.15 *val4)+ (0.7 * val1) + (0.15 * val2);
sum2 = (0.25 * val5)+(0.75 * val1);//mixing

myservo1.write(sum1);
//set the servo position according to the scaled value
delay(15);

myservo2.write(sum2);
//set the main rotor to the potentiometer
delay (15);
}

I recommend adding some debug prints.
And posting code in a code box.

  val2=analogRead(gyropin);
  //(value between 0 and 1023)- to read the value of the potentiometer
 
  val2=map(val2,0,1023,0,179);
  //(value between 0 and 180)-scale it to use with servo

What relationship between the gyro output and the servo angle are you expecting to maintain?

  sum1 = (0.15 *val4)+ (0.7 * val1) + (0.15 * val2);

val1 and val2 are in the range 0 to 179. val4 is in the range 1321 to 1500. This weighted average doesn't make sense.

The code is given by my teacher. Maybe there is some slight errors . So how can i correct it ?
One more question is the code given is trying to obtain the angle of the servo ?

So how can i correct it ?

Did you read reply #1? First, you figure out where it is not doing what you want. Then, you figure out why. Then, you fix the problem.

One more question is the code given is trying to obtain the angle of the servo ?

Well, it isn't getting a weather report...