From 7ee090043a7d0d4666d3a6a30a56aff2ec07198d Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 6 Dec 2024 20:19:52 +0100 Subject: [PATCH] FAN_ENABLED activated --- include/controller.h | 2 +- src/main.cpp | 73 +++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/include/controller.h b/include/controller.h index ea2c033..a0acf9c 100644 --- a/include/controller.h +++ b/include/controller.h @@ -20,6 +20,6 @@ #define WS2812SINGLE_LEDS 3 #define WS2812STRIP_GPIO_PIN D5 -#define WS2812STRIP_LEDS 13 +#define WS2812STRIP_LEDS 20 #endif /* End FANLEDCTL_PINS */ \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a337ca0..0449de1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ /****************************************************************************** * DEFINES ******************************************************************************/ +#define FAN_ENABLED #define DELAY_TIME 1000 /**< time between measurements [ms] */ #define MIN_FAN_SPEED_PERCENT 24 /**< minimum fan speed [%] */ @@ -31,11 +32,42 @@ Adafruit_NeoPixel* singleLed; OneWire oneWire(GPIO_DS18B20); DallasTemperature sensors(&oneWire); +#ifdef FAN_ENABLED +/** + * @brief Get the Fan Speed in round per minutes + * + * @return int + */ +int getFanSpeedRpm() { + int highTime = pulseIn(SIGNAL_PIN, HIGH); + int lowTime = pulseIn(SIGNAL_PIN, LOW); + int period = highTime + lowTime; + if (period == 0) { + return 0; + } + float freq = 1000000.0 / (float)period; + return (freq * 60.0) / 2.0; // two cycles per revolution +} + +/** + * @brief Set the Fan Speed + * + * @param p expected percentage + */ +void setFanSpeedPercent(int p) { + int value = (p / 100.0) * 255; + analogWrite(FAN_PIN, value); +} +#else + uint8_t mRainbowIndex; +#endif + /** * @brief Called once at start * Initialize hardware pins */ -void setup() { +void setup() +{ pixels = new Adafruit_NeoPixel(WS2812STRIP_LEDS, WS2812STRIP_GPIO_PIN, NEO_GRB + NEO_KHZ400); singleLed = new Adafruit_NeoPixel(WS2812SINGLE_LEDS, WS2812SINGLE_GPIO_PIN, NEO_GRB + NEO_KHZ400); @@ -51,6 +83,7 @@ void setup() { pinMode(SIGNAL_PIN, INPUT); #else Serial.println(F("\nFAN NOT enabled")); + mRainbowIndex = 0; #endif pixels->begin(); @@ -80,34 +113,6 @@ void setup() { singleLed->show(); } -#ifdef FAN_ENABLED -/** - * @brief Get the Fan Speed in round per minutes - * - * @return int - */ -int getFanSpeedRpm() { - int highTime = pulseIn(SIGNAL_PIN, HIGH); - int lowTime = pulseIn(SIGNAL_PIN, LOW); - int period = highTime + lowTime; - if (period == 0) { - return 0; - } - float freq = 1000000.0 / (float)period; - return (freq * 60.0) / 2.0; // two cycles per revolution -} - -/** - * @brief Set the Fan Speed - * - * @param p expected percentage - */ -void setFanSpeedPercent(int p) { - int value = (p / 100.0) * 255; - analogWrite(FAN_PIN, value); -} - -#endif float readTemperature(void) { @@ -148,13 +153,13 @@ void loop() #ifdef FAN_ENABLED actualFanSpeedRpm = getFanSpeedRpm(); - pixels->fill(pixels.Color(255, 0,0)); + pixels->fill(Color(255, 0,0)); pixels->setBrightness(actualFanSpeedRpm); -#else - uint8_t index = (uint8_t) ((actualFanSpeedRpm + 1) % 256); - RainbowCycle(pixels, &index); -#endif pixels->show(); +#else + RainbowCycle(pixels, &mRainbowIndex); + Serial.print(mRainbowIndex); +#endif #ifdef FAN_ENABLED