code problem

hi people im having a bit of trouble complying my code for the Arduino. i have built two codes for my Peltier one controlling if for hot and one controlling it for the cold. im wondering if the is any way i can combine the two and have a function which will allow me to switch my tow codes rather than me uploading them at different times.

//peltier for hot

float tempC;
int tempPin = 0; // Temp output plugged into analogue 0
int peltier = 9; // PWM Pin 9 connected to the base of the transistor
int fan = 3;// small fan is connected to pin 5

void setup()
{
Serial.begin(9600); 
pinMode(peltier, OUTPUT);
pinMode(fan, OUTPUT);

}

// write loop to tell arduino what to do with temp feed back

void loop()
{
Serial.print(" Temperature= ");
tempC = analogRead(tempPin); 
// obtaining temp pin reading and setting it equal to temp C varialble

tempC = (5.0*tempC*100)/1024.0; 
// it will convert the analog input to a temperature in celcius

Serial.print((byte)tempC); 
// will output the converted temperatur to PC.
if (tempC >45)
{
digitalWrite(fan, HIGH);
digitalWrite(peltier, LOW);
{
delay (500);
}
}

else
{
digitalWrite(fan, LOW);
digitalWrite(peltier, HIGH);
{
delay (1000);
}
}

}
Cold code 
// Define Variables

float tempC;
int tempPin = 1; // Temp output plugged into analogue 1
int peltier = 9; // PWM Pin 9 connected to the base of the transistor
int fan = 3;// 

void setup()
{
Serial.begin(9600); 
pinMode(peltier, OUTPUT);
pinMode(fan, OUTPUT);

}

// write loop to tell arduino what to do with temp feed back

void loop()
{

Serial.print(" Temp= ");
tempC = analogRead(tempPin); // obtaining temp pin reading and setting it equal to temp C varialble
tempC = (5.0*tempC*100)/1024.0; // it will convert the analog input to a temperature in celcius
Serial.print((byte)tempC); // will output the converted temperatur to PC.
if (tempC <25)
{
digitalWrite(fan, LOW);
digitalWrite(peltier, LOW);

}

else
{
digitalWrite(fan, HIGH);
digitalWrite(peltier, HIGH);

}
{
delay (500);
}
}

Implement different operation modes in your sketch (you will probably want an off mode too). Then decide how you want to tell your Arduino what mode to use. You might need some hysteresis in your temperature control.

if (mode == HEAT) {
  // do whatever to implement heat mode
}
else if (mode == COOL) {
  // do whatever to implement cool mode
}

hi thanks for that i will give it a try over the weekend :slight_smile: much appreciated