code problem
hi people im having bit of trouble complying code arduino. have built 2 codes peltier 1 controlling if hot , 1 controlling cold. im wondering if way can combine 2 , have function allow me switch tow codes rather me uploading them @ different times.
code: [select]
//peltier hot
float tempc;
int temppin = 0; // temp output plugged analogue 0
int peltier = 9; // pwm pin 9 connected base of transistor
int fan = 3;// small fan connected pin 5
void setup()
{
serial.begin(9600);
pinmode(peltier, output);
pinmode(fan, output);
}
// write loop tell arduino temp feed back
void loop()
{
serial.print(" temperature= ");
tempc = analogread(temppin);
// obtaining temp pin reading , setting equal temp c varialble
tempc = (5.0*tempc*100)/1024.0;
// convert analog input temperature in celcius
serial.print((byte)tempc);
// output converted temperatur pc.
if (tempc >45)
{
digitalwrite(fan, high);
digitalwrite(peltier, low);
{
delay (500);
}
}
else
{
digitalwrite(fan, low);
digitalwrite(peltier, high);
{
delay (1000);
}
}
}
code: [select]
cold code
// define variables
float tempc;
int temppin = 1; // temp output plugged analogue 1
int peltier = 9; // pwm pin 9 connected base of transistor
int fan = 3;//
void setup()
{
serial.begin(9600);
pinmode(peltier, output);
pinmode(fan, output);
}
// write loop tell arduino temp feed back
void loop()
{
serial.print(" temp= ");
tempc = analogread(temppin); // obtaining temp pin reading , setting equal temp c varialble
tempc = (5.0*tempc*100)/1024.0; // convert analog input temperature in celcius
serial.print((byte)tempc); // output converted temperatur pc.
if (tempc <25)
{
digitalwrite(fan, low);
digitalwrite(peltier, low);
}
else
{
digitalwrite(fan, high);
digitalwrite(peltier, high);
}
{
delay (500);
}
}
implement different operation modes in sketch (you want off mode too). decide how want tell arduino mode use. might need hysteresis in temperature control.
code: [select]
if (mode == heat) {
// whatever implement heat mode
}
else if (mode == cool) {
// whatever implement cool mode
}
Arduino Forum > Using Arduino > Programming Questions > code problem
arduino
Comments
Post a Comment