FAN_ENABLED activated

This commit is contained in:
Ollo 2024-12-06 20:19:52 +01:00
parent e7a2eab923
commit 7ee090043a
2 changed files with 40 additions and 35 deletions

View File

@ -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 */

View File

@ -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