FAN_ENABLED activated
This commit is contained in:
parent
e7a2eab923
commit
7ee090043a
@ -20,6 +20,6 @@
|
|||||||
#define WS2812SINGLE_LEDS 3
|
#define WS2812SINGLE_LEDS 3
|
||||||
|
|
||||||
#define WS2812STRIP_GPIO_PIN D5
|
#define WS2812STRIP_GPIO_PIN D5
|
||||||
#define WS2812STRIP_LEDS 13
|
#define WS2812STRIP_LEDS 20
|
||||||
|
|
||||||
#endif /* End FANLEDCTL_PINS */
|
#endif /* End FANLEDCTL_PINS */
|
73
src/main.cpp
73
src/main.cpp
@ -13,6 +13,7 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
#define FAN_ENABLED
|
||||||
|
|
||||||
#define DELAY_TIME 1000 /**< time between measurements [ms] */
|
#define DELAY_TIME 1000 /**< time between measurements [ms] */
|
||||||
#define MIN_FAN_SPEED_PERCENT 24 /**< minimum fan speed [%] */
|
#define MIN_FAN_SPEED_PERCENT 24 /**< minimum fan speed [%] */
|
||||||
@ -31,11 +32,42 @@ Adafruit_NeoPixel* singleLed;
|
|||||||
OneWire oneWire(GPIO_DS18B20);
|
OneWire oneWire(GPIO_DS18B20);
|
||||||
DallasTemperature sensors(&oneWire);
|
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
|
* @brief Called once at start
|
||||||
* Initialize hardware pins
|
* Initialize hardware pins
|
||||||
*/
|
*/
|
||||||
void setup() {
|
void setup()
|
||||||
|
{
|
||||||
pixels = new Adafruit_NeoPixel(WS2812STRIP_LEDS, WS2812STRIP_GPIO_PIN, NEO_GRB + NEO_KHZ400);
|
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);
|
singleLed = new Adafruit_NeoPixel(WS2812SINGLE_LEDS, WS2812SINGLE_GPIO_PIN, NEO_GRB + NEO_KHZ400);
|
||||||
|
|
||||||
@ -51,6 +83,7 @@ void setup() {
|
|||||||
pinMode(SIGNAL_PIN, INPUT);
|
pinMode(SIGNAL_PIN, INPUT);
|
||||||
#else
|
#else
|
||||||
Serial.println(F("\nFAN NOT enabled"));
|
Serial.println(F("\nFAN NOT enabled"));
|
||||||
|
mRainbowIndex = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pixels->begin();
|
pixels->begin();
|
||||||
@ -80,34 +113,6 @@ void setup() {
|
|||||||
singleLed->show();
|
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)
|
float readTemperature(void)
|
||||||
{
|
{
|
||||||
@ -148,13 +153,13 @@ void loop()
|
|||||||
|
|
||||||
#ifdef FAN_ENABLED
|
#ifdef FAN_ENABLED
|
||||||
actualFanSpeedRpm = getFanSpeedRpm();
|
actualFanSpeedRpm = getFanSpeedRpm();
|
||||||
pixels->fill(pixels.Color(255, 0,0));
|
pixels->fill(Color(255, 0,0));
|
||||||
pixels->setBrightness(actualFanSpeedRpm);
|
pixels->setBrightness(actualFanSpeedRpm);
|
||||||
#else
|
|
||||||
uint8_t index = (uint8_t) ((actualFanSpeedRpm + 1) % 256);
|
|
||||||
RainbowCycle(pixels, &index);
|
|
||||||
#endif
|
|
||||||
pixels->show();
|
pixels->show();
|
||||||
|
#else
|
||||||
|
RainbowCycle(pixels, &mRainbowIndex);
|
||||||
|
Serial.print(mRainbowIndex);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef FAN_ENABLED
|
#ifdef FAN_ENABLED
|
||||||
|
Loading…
Reference in New Issue
Block a user