Combining various codes...URGENT HELP!

Hi

I need some serious help with my coding. Basically, I am creating an interactive installation that needs various codes running all at once, I have tried combining them but it does not seem to work. Here are all the codes I need to be running at the same time.

I will post the code below as it is pretty long!

any help would be very much appreciated

Thanks

Andy

here is the code I have written so far:
// Printhead Gram
int PrintheadPin = 13; // PRINTHEAD connected to digital pin 13

//Crank Gram
int FatmotorPin = 12; // PRINTHEAD connected to digital pin 13

// Slide Projector
#include <buttons.h>
#include <Servo.h>

Button B;
Servo myservo; // create servo object to control a servo

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

//8mm Projector - Twins
#include <Servo.h>

Servo projectorservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

//8mm Projector - Blind man
#include <Servo.h>

Servo projectorservo2; // create servo object to control a servo

int potpin2 = 1 ; // analog pin used to connect the potentiometer
int val2; // variable to read the value from the analog pin

void setup()
// Printhead gram
{
{
pinMode(PrintheadPin, OUTPUT); // sets the digital pin as output
}
// Slide Projector
{
B.assign(7);
B.setMode(OneShotTimer);
B.setTimer(1500);
B.setRefresh(500);

myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
//Crank gram
{
pinMode(FatmotorPin, OUTPUT); // sets the digital pin as output
}
// 8mm Projector - Twins
{
projectorservo.attach(10); // attaches the servo on pin 9 to the servo object
}
// 8mm Projector - Blind man
{
projectorservo2.attach(11); // attaches the servo on pin 9 to the servo object
}
}

void loop()
{
//Printhead gram

{
digitalWrite(PrintheadPin, HIGH); // sets the PRINTHEAD on
delay(4000); // waits for 4 seconds
digitalWrite(PrintheadPin, LOW); // sets the PRINTHEAD off
delay(180000); // waits for 1:80
}

//Crank gram

{
digitalWrite(FatmotorPin, HIGH); // sets the PRINTHEAD on
delay(200000); // waits for 2 minutes
digitalWrite(FatmotorPin, LOW); // sets the PRINTHEAD off
delay(180000); // waits for 1:80
}
// Slide Projector

switch(B.check()) {
case ON:
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{

myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(200);
}
for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
{
delay(200);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(49000); // delays the servo at 20 degrees
myservo.write(20); // puts the servo at 20 in a stable manner

break;
}
// 8mm Projector - Twins
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 50); // scale it to use it with the servo (value between 0 and 180)
projectorservo.write(val); // sets the servo position according to the scaled value
delay(0);
}

Well, the obvious question is:
How is it supposed to work?
What are you trying to achieve?

If you factorised your program, it would be a lot easier to read, and also to debug.

Instead of repeatedly writing:

for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
           {   
                 
                 myservo.write(pos);     // tell servo to go to position in variable 'pos' 
                 delay(200); 
               }

It would be much clearer to write a simple function to do it.

I think I already pointed out that this:

 for(pos = 0; pos < 20; pos += 1) // goes from 0 degrees to 20 degrees
           {
                 delay(200);
                 myservo.write(pos);     // tell servo to go to position in variable 'pos' 
                       delay(49000); // delays the servo at 20 degrees
                   myservo.write(20); // puts the servo at 20 in a stable manner
           
           break;
}

Is almost certainly not what you intended.
The "break" causes the "for" loop to exit on the first pass through.
Consistent indentation helps to spot mistakes like this.

I think you need to be a little more specifik about what it is you want to achieve and what it is that does not work.

One thing you should be aware of is the when you call delay(180000) then Arduino will do absolutely nothing for 180 seconds. It will not go on to execute other parts of the code, it will literally pause all execution.

Try to check the playground for the example on how to blink a LED without using the delay() function, this can give you an idea on how to bypass that problem.

Thanks MikMo and AWOL

Well...specifically this is what I intend to do.

2 seperate potentiometers controlling seperate servo's.

A push button controlling a servo to do 32, 0-20 degree turns and pause for 49000.

2 seperate relay circuits triggering 2 seperate motors on a timed cycle.

Obviouslly this relies on delay, but hopefully there is a way around this. Im still pretty confused on how to achieve this lengthy delay in certain parts of the code without interupting the other loops.

Basically the relays are not clicking, so Im guessing the delay function is my problem.

Thanks again

Andy

The simplest way to think about doing multiple things is to make an analogy with everyday life.

If you're making breakfast, you might want a 3 minute boiled egg and some toast.
Now, the toast may take less than 3 minutes, so, start the egg and set a timer for 180 seconds.
You could do this by noting the time now, and then looking at a stopwatch to see if you've reached (now + 180) every time you're not doing anything else.
Put the bread in the toaster.
does time now = (now + 180)?
No.
Is the toast ready?
No.
Start to make a cup of tea.
Does time now = (now + 180)?
... and so on.

Think how "loop ()" works - as soon as "loop ()" has finished, it is called again.
If you need to do something 32 times, put it in a loop (if possible), don't simply cut and paste - this wastes memory.
Check that your switch statement does what you think it does.
It isn't necessary to "include <servo.h>" more than once.
Cut down on the "{...}" clutter; mostly they're unnecessary for inline stuff.

[EDIT]
delay(200000); // waits for 2 minutes
is incorrect - there are 120000 milliseconds in two minutes.
If you're doing stuff like this, it can be useful to define a simple aide- memoire:
#define SECONDS_IN_A_MINUTE 60
#define MILLIS 1000
#define delaySeconds(x) delay((x) * MILLIS)
#define delayMinutes(x) delaySeconds((x)* SECONDS_IN_A_MINUTE)
. ..
delayMinutes (2);

that way, it's clearer to you what you wanted to happen