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 "slowPWM.h"
// Pin definitions
#define encoderCLK 2
#define encoderDT 3
#define encoderBTN 4
#define kettlePWM 5
// Global variables.
byte KettleDuty = 0;
bool KettleOn = false;
@ -122,9 +116,9 @@ void UpdateBoilKettle(){
}
if (KettleOn) {
boilPWM.compute(KettleDuty);
digitalWrite(kettlePWM, boilPWM.compute(KettleDuty));
} else {
boilPWM.compute(0);
digitalWrite(kettlePWM, boilPWM.compute(0));
}
}

View File

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