Make slowPWM::compute return state instead of changing pin.

I just like it better this way.
This commit is contained in:
Chris Giacofei 2022-01-15 18:10:46 -05:00
parent 8908eccdb6
commit 180e3b065f
2 changed files with 5 additions and 10 deletions

View File

@ -16,12 +16,6 @@
#include "button.h" #include "button.h"
#include "slowPWM.h" #include "slowPWM.h"
// Pin definitions
#define encoderCLK 2
#define encoderDT 3
#define encoderBTN 4
#define kettlePWM 5
// Global variables. // Global variables.
byte KettleDuty = 0; byte KettleDuty = 0;
bool KettleOn = false; bool KettleOn = false;
@ -122,9 +116,9 @@ void UpdateBoilKettle(){
} }
if (KettleOn) { if (KettleOn) {
boilPWM.compute(KettleDuty); digitalWrite(kettlePWM, boilPWM.compute(KettleDuty));
} else { } else {
boilPWM.compute(0); digitalWrite(kettlePWM, boilPWM.compute(0));
} }
} }

View File

@ -20,7 +20,7 @@ class slowPWM {
Serial.println("Setup PWM"); Serial.println("Setup PWM");
} }
void compute(byte duty) { byte compute(byte duty) {
unsigned long onTime = (duty * period) / 100; unsigned long onTime = (duty * period) / 100;
unsigned long offTime = period - onTime; unsigned long offTime = period - onTime;
unsigned long currentTime = millis(); unsigned long currentTime = millis();
@ -35,7 +35,8 @@ class slowPWM {
lastSwitchTime = currentTime; lastSwitchTime = currentTime;
outputState = HIGH; outputState = HIGH;
} }
digitalWrite(outputPin, outputState);
return outputState;
} }
}; };
#endif #endif