From c87c46ce9c025fae5609a48bd05d2d2a375733c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Mon, 17 Feb 2025 20:08:07 +0100 Subject: [PATCH] Fermenter PWM 100Hz --- src/patrix/PWMOutput.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/patrix/PWMOutput.h b/src/patrix/PWMOutput.h index b30dac3..b11b910 100644 --- a/src/patrix/PWMOutput.h +++ b/src/patrix/PWMOutput.h @@ -10,18 +10,21 @@ class PWMOutput { String name; + uint32_t frequency = 0; + int value = 0; double percent = 0; public: - explicit PWMOutput(const uint8_t gpio, String name): gpio(gpio), name(std::move(name)) { + explicit PWMOutput(const uint8_t gpio, String name, uint32_t frequency) : gpio(gpio), name(std::move(name)), frequency(frequency) { // } void setup() { analogWriteResolution(CONTROL_PWM_BITS); + analogWriteFreq(frequency); setValue(0); } @@ -31,8 +34,8 @@ public: analogWrite(gpio, value); } - void setPercent(const double percent) { - setValue(static_cast(percent / 100.0 * CONTROL_PWM_MAX)); + void setPercent(const double newPercent) { + setValue(static_cast(newPercent / 100.0 * CONTROL_PWM_MAX)); } [[nodiscard]] double getPercent() const {