From ff48bcb52dd77bb456c42c2753a5bff18a7ec7b4 Mon Sep 17 00:00:00 2001 From: Chris Giacofei Date: Fri, 14 Jan 2022 13:50:41 -0500 Subject: [PATCH] Line endings --- .gitattributes | 1 + boil_kettle/slowPWM.h | 80 ++++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/boil_kettle/slowPWM.h b/boil_kettle/slowPWM.h index ba30be7..a1e7c69 100644 --- a/boil_kettle/slowPWM.h +++ b/boil_kettle/slowPWM.h @@ -1,39 +1,41 @@ -#ifndef SLOWPWM_h -#define SLOWPWM_h - -#include - -class slowPWM { - private: - byte outputPin; - byte dutyCycle; - unsigned long period; - unsigned long lastSwitchTime; - byte outputState; - - public: - void begin(byte pin, unsigned long per) { - outputPin = pin; - period = per; - lastSwitchTime = 0; - outputState = LOW; - pinMode(pin, OUTPUT); - } - - void compute(byte duty) { - unsigned long onTime = (dutyCycle * period) / 100; - unsigned long offTime = period - onTime; - unsigned long currentTime = millis(); - - if (outputState == HIGH && (currentTime - lastSwitchTime >= onTime)) { - lastSwitchTime = currentTime; - outputState = LOW; - } - if (outputState == LOW && (currentTime - lastSwitchTime >= offTime)) { - lastSwitchTime = currentTime; - outputState = HIGH; - } - digitalWrite(outputPin, outputState); - } -}; -#endif +#ifndef SLOWPWM_h +#define SLOWPWM_h + +#include + +class slowPWM { + private: + byte outputPin; + unsigned long period; + unsigned long lastSwitchTime; + byte outputState; + + public: + void begin(byte pin, unsigned long per) { + outputPin = pin; + period = per; + lastSwitchTime = 0; + outputState = LOW; + pinMode(pin, OUTPUT); + Serial.println("Setup PWM"); + } + + void compute(byte duty) { + unsigned long onTime = (duty * period) / 100; + unsigned long offTime = period - onTime; + unsigned long currentTime = millis(); + + if (duty == 0) { + outputState = LOW; + } else if (outputState == HIGH && (currentTime - lastSwitchTime >= onTime)) { + lastSwitchTime = currentTime; + outputState = LOW; + + } else if (outputState == LOW && (currentTime - lastSwitchTime >= offTime)) { + lastSwitchTime = currentTime; + outputState = HIGH; + } + digitalWrite(outputPin, outputState); + } +}; +#endif