diff --git a/include/controller.h b/include/controller.h index 031a0b7..eba3a75 100644 --- a/include/controller.h +++ b/include/controller.h @@ -16,4 +16,7 @@ #define GPIO_DS18B20 D2 /**< One-Wire used for Dallas temperature sensor */ +#define GPIO_WS2812_PIN1 D3 +#define WS2812_LEDS1 1 + #endif /* End FANLEDCTL_PINS */ \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index ef479a2..b9e9b55 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,4 +14,5 @@ board = d1_wroom_02 framework = arduino lib_deps = OneWire - DallasTemperature \ No newline at end of file + DallasTemperature + adafruit/Adafruit NeoPixel \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 282f91d..effc824 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,14 @@ #include #include #include +#include #include "controller.h" +/****************************************************************************** + * DEFINES + ******************************************************************************/ + #define DELAY_TIME 1000 /**< time between measurements [ms] */ #define MIN_FAN_SPEED_PERCENT 24 /**< minimum fan speed [%] */ #define MIN_TEMP 25 /**< turn fan off below [deg C] */ @@ -12,6 +17,10 @@ #define TEMP_SENSOR_MEASURE_SERIES 5 /**< Maximum resets */ +/****************************************************************************** + * LOCAL VARIABLES + ******************************************************************************/ +Adafruit_NeoPixel* pPixels = NULL; OneWire oneWire(GPIO_DS18B20); DallasTemperature sensors(&oneWire); @@ -25,6 +34,17 @@ void setup() { /* Setup FAN Control */ pinMode(FAN_PIN, OUTPUT); pinMode(SIGNAL_PIN, INPUT); + + + pPixels = new Adafruit_NeoPixel(WS2812_LEDS1, GPIO_WS2812_PIN1, NEO_RGB + NEO_KHZ800); + + pPixels->begin(); + pPixels->clear(); + pPixels->fill(pPixels->Color(255,0,0)); + pPixels->setBrightness(100); + pPixels->show(); + + /* Initialize Temperature sensor */ sensors.begin(); for(int j=0; j < TEMP_SENSOR_MEASURE_SERIES && sensors.getDeviceCount() == 0; j++) @@ -96,6 +116,10 @@ void loop() { fanSpeedPercent = (100 - MIN_FAN_SPEED_PERCENT) * (temp - MIN_TEMP) / (MAX_TEMP - MIN_TEMP) + MIN_FAN_SPEED_PERCENT; } + pPixels->fill(pPixels->Color(255,0,0)); + pPixels->setBrightness(fanSpeedPercent); + pPixels->show(); + Serial.print(fanSpeedPercent); Serial.print("%;"); setFanSpeedPercent(fanSpeedPercent);