need help on combining code in one sketch

ive tried both of these seperately and they work but once i put them in the same sketch only one of them works

#include <Servo.h>
Servo servoMain; // Define Servo

void setup()
{
servoMain.attach(7); // servo on digital pin 7

}

void loop()
{
servoMain.write(30); // Turn Servo Left to 30 degrees
delay(1000); // Wait 1 second
servoMain.write(0); // Turn Servo Left to 0 degrees
delay(1000); // Wait 1 second
servoMain.write(30); // Turn Servo back to center position (30 degrees)
delay(1000); // Wait 1 second
servoMain.write(15); // Turn Servo Right to 15 degrees
delay(1000); // Wait 1 second
servoMain.write(15); // Turn Servo Right to 15 degrees
delay(1000); // Wait 1 second
servoMain.write(30); // Turn Servo back to center position (30 degrees)
delay(1000); // Wait 1 second

}

int led = 13;
int led2 = 12;
int led3 = 11;

// the setup routine runs once when you press reset:
void Msetup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}

// the loop routine runs over and over again forever:
void Mloop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(50);
{digitalWrite(led2, HIGH);
delay(50);
digitalWrite(led2, LOW);
delay(50);}
{digitalWrite(led3, HIGH);
delay(50);
digitalWrite(led3, LOW);
delay(50);}// wait for a second
}

once i put them in the same sketch only one of them works

I did something mysterious that I don't intend to show you.
The code does something that I am not going to explain.

I want to know why.

Did I summarize your post correctly?

PaulS:
Did I summarize your post correctly?

No.

OP did show the code, with one of each setup() and loop() with an M in front, so neither of those is illegal hence it compiles, but don't do anything, hence OP's view that only one works.

manor_royal:
No.

OP did show the code, with one of each setup() and loop() with an M in front, so neither of those is illegal hence it compiles, but don't do anything, hence OP's view that only one works.

I missed the Ms. It looked to me like OP posted both programs incorrectly.

OP. THAT is why we expect you to use code tags.

It does no good to define a function and then never call it.

Centarious as PaulS points out, you need to call those two new functions Msetup() and Mloop(). But that's not really how you should go about things.

One way to join sketches together is to copy the contents of the 2x loop()s into loop() of a 3rd sketch, and ditto with setup(). Then in the new setup() and loop() you order things so that the activities from the 2 original sketches work in a harmonised manner.

But it's nowhere near as simple as that in your case. The huge number of huge delay()s in both your sketches means the servo and led actions will not "interleave" at all, even if you mix the led lines into the servo lines. Nothing happens during a delay(), so while it's (say) putting an led on with a delay(), it's not looking at what to do to the servo.

I don't see an easy way out of this other than completely re-thinking your approach to use the millis()-based technique of BlinkWithOutDelay which is demonstrated here by Robin2.

It looks like you only half read Merging Code

If you follow that then first one function will work which will take 7 seconds and then the second function will run which will take 0.3 second.

By the way this line:-
delay(50);}// wait for a second
will not wait for a second but 50mS.

I am edited the code for you. maintain intent in your code.

#include <Servo.h>
Servo servoMain; // Define Servo

int led = 13;
int led2 = 12;
int led3 = 11;

void setup()
{
   servoMain.attach(7); // servo on digital pin 7
   pinMode(led, OUTPUT);
   pinMode(led2, OUTPUT);
   pinMode(led3, OUTPUT);
}

void loop()
{
   servoMain.write(30);  // Turn Servo Left to 30 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(0);   // Turn Servo Left to 0 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(30);  // Turn Servo back to center position (30 degrees)
   delay(1000);          // Wait 1 second
   servoMain.write(15); // Turn Servo Right to 15 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(15); // Turn Servo Right to 15 degrees
   delay(1000);          // Wait 1 second
   servoMain.write(30);  // Turn Servo back to center position (30 degrees)
   delay(1000);          // Wait 1 second
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(50);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(50);
   digitalWrite(led2, HIGH);
   delay(50);
   digitalWrite(led2, LOW);
   delay(50);
   digitalWrite(led3, HIGH);
   delay(50);
   digitalWrite(led3, LOW);
   delay(50);// wait for a second
}

delay(50); is not for a second. it is only 50 milli second.

Why you making
Msetup(){
}
Mloop(){
}
this is not recommend and this is not like. if you want run both simultaneously then you can go for interrupt or task. that only making multitasking