Arduino-PID-Library icon indicating copy to clipboard operation
Arduino-PID-Library copied to clipboard

Set pinMode(RELAY_PIN,OUTPUT) & add RELAY_ON /RELAY_OFF per https://github.com/br3ttb/Arduino-PID-Lib…

Open drf5n opened this issue 2 years ago • 0 comments

Flesh out the logic of https://github.com/br3ttb/Arduino-PID-Library/blob/master/examples/PID_RelayOutput/PID_RelayOutput.ino to clearly accommodate both active-LOW and active-HIGH relays per https://github.com/br3ttb/Arduino-PID-Library/issues/136

diff --git a/examples/PID_RelayOutput/PID_RelayOutput.ino b/examples/PID_RelayOutput/PID_RelayOutput.ino
index 17fbe1a..7c19203 100644
--- a/examples/PID_RelayOutput/PID_RelayOutput.ino
+++ b/examples/PID_RelayOutput/PID_RelayOutput.ino
@@ -18,6 +18,8 @@
 
 #define PIN_INPUT 0
 #define RELAY_PIN 6
+#define RELAY_ON LOW
+#define RELAY_OFF HIGH
 
 //Define Variables we'll be connecting to
 double Setpoint, Input, Output;
@@ -55,8 +57,14 @@ void loop()
   { //time to shift the Relay Window
     windowStartTime += WindowSize;
   }
-  if (Output < millis() - windowStartTime) digitalWrite(RELAY_PIN, HIGH);
-  else digitalWrite(RELAY_PIN, LOW);
+  if (Output > millis() - windowStartTime)
+  {
+    digitalWrite(RELAY_PIN, RELAY_ON);
+  }
+  else
+  {
+    digitalWrite(RELAY_PIN, RELAY_OFF);
+  }
 
 }

drf5n avatar May 01 '23 15:05 drf5n