This commit is contained in:
jamesprior 2013-01-23 17:49:07 -08:00
commit e204c2b3e9

View File

@ -24,6 +24,7 @@ double Setpoint, Input, Output;
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT); PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
int WindowSize = 5000; int WindowSize = 5000;
int minWindow = 500;
unsigned long windowStartTime; unsigned long windowStartTime;
void setup() void setup()
{ {
@ -42,16 +43,16 @@ void setup()
void loop() void loop()
{ {
Input = analogRead(0); Input = analogRead(0);
myPID.Compute();
/************************************************ /************************************************
* turn the output pin on/off based on pid output * turn the output pin on/off based on pid output
************************************************/ ************************************************/
if(millis() - windowStartTime>WindowSize) if(millis() - windowStartTime>WindowSize)
{ //time to shift the Relay Window { //time to shift the Relay Window and recalculate
windowStartTime += WindowSize; windowStartTime += WindowSize;
myPID.Compute();
} }
if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH); if(Output > minWindow && Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
else digitalWrite(RelayPin,LOW); else digitalWrite(RelayPin,LOW);
} }