SetControllerDirection in a Loop?

Hello and Thank you for reading this.

Is there any reason I cannot change the controller direction in a PID loop??? I want output if the Input is ABOVE or BELOW the setpoint. (IE a thermastat that heats and cools)

********************************************************
 * PID Basic Example
 * Reading analog input 0 to control analog PWM output 3
 ********************************************************/

#include <PID_v1.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(0);
  Setpoint = 100;

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}

void loop()
{
  Input = analogRead(0);

if(SetPoint>InpuT){SetControllerDirection(DIRECT);}
if(Input>SetPoint){SetControllerDirection(REVERSE);}

  myPID.Compute();
  analogWrite(3,Output);
}

Can I be clear ? Do you want a cooler turned on if the output is above the setpoint and a heater turned on if the output is below the setpoint ? If so, then can you use 2 PIDs ?

Hello:

Is there any reason I cannot change controller direction in a PID loop? I bascially want a thermastat that will heat up to the setpoint and then cool back down…

/********************************************************
 * PID Basic Example
 * Reading analog input 0 to control analog PWM output 3
 ********************************************************/

#include <PID_v1.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(0);
  Setpoint = 100;

  //turn the PID on
  myPID.SetMode(AUTOMATIC);
}

void loop()
{
if(Setpoint>=Input){SetControllerDirection(Direct);}
if(Input>Setpoint){SetCtonrollerDirection(Reverse);}
  Input = analogRead(0);
  myPID.Compute();
  analogWrite(3,Output);
}
[code/]

@house231, do not cross-post. Threads merged.

UKHeliBob: If so, then can you use 2 PIDs ?

Split range output is also a good choice.

Sorry about the cross post, it was not intentional, the server has been on the fritz for half a day.

Yes I want a cooler turned on if the output is above the setpoint and a heater turned on if the output is below the setpoint. The switching of the SetControllerDirect does seem to work but I dont know if that is screwing things up somehow. I am not sure how to code for a split range or two separate PID