From f761d3349ea38f806f2adc00e30e4dd82f174814 Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 6 Dec 2024 20:33:24 +0100 Subject: [PATCH] Read RPM each 100 cycles --- src/main.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0449de1..9622c7d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,6 +22,7 @@ #define INVALID_TEMP (MAX_TEMP+MAX_TEMP) /**< Invalid temperature (on sensor failures)*/ #define TEMP_SENSOR_MEASURE_SERIES 5 /**< Maximum resets */ +#define FAN_RPM_READLEVEL 100 /****************************************************************************** * LOCAL VARIABLES @@ -136,12 +137,14 @@ float readTemperature(void) */ void loop() { + static int i = 0; + static int actualFanSpeedRpm = -1; float temp = readTemperature(); Serial.print(temp); Serial.print(";"); - int fanSpeedPercent, actualFanSpeedRpm = 0; + int fanSpeedPercent; if (temp < MIN_TEMP) { fanSpeedPercent = 0; @@ -152,7 +155,21 @@ void loop() } #ifdef FAN_ENABLED - actualFanSpeedRpm = getFanSpeedRpm(); + if (actualFanSpeedRpm == 0) + { + if (i > FAN_RPM_READLEVEL) + { + actualFanSpeedRpm = getFanSpeedRpm(); + i = 0; + } + i++; + } + else + { + actualFanSpeedRpm = getFanSpeedRpm(); + i = 0; + } + pixels->fill(Color(255, 0,0)); pixels->setBrightness(actualFanSpeedRpm); pixels->show(); @@ -175,9 +192,5 @@ void loop() singleLed->fill(Color(0,128,128)); singleLed->setBrightness(fanSpeedPercent); - singleLed->show(); - -#ifdef FAN_ENABLED - delay(DELAY_TIME); -#endif + singleLed->show(); }