Refactored to single instance of Adafruit_NeoPixel

This commit is contained in:
Ollo 2024-12-04 19:08:17 +01:00
parent c48d977f42
commit c8e81310cc
2 changed files with 25 additions and 16 deletions

View File

@ -16,10 +16,10 @@
#define GPIO_DS18B20 D2 /**< One-Wire used for Dallas temperature sensor */ #define GPIO_DS18B20 D2 /**< One-Wire used for Dallas temperature sensor */
#define GPIO_WS2812_PIN1 D3 #define WS2812SINGLE_GPIO_PIN D3
#define WS2812_LEDS1 1 #define WS2812SINGLE_LEDS 1
#define GPIO_WS2812_PIN2 D4 #define WS2812STRIP_GPIO_PIN D4
#define WS2812_LEDS2 10 #define WS2812STRIP_LEDS 10
#endif /* End FANLEDCTL_PINS */ #endif /* End FANLEDCTL_PINS */

View File

@ -3,7 +3,10 @@
#include <OneWire.h> #include <OneWire.h>
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#include "controller.h" #include "controller.h"
/******************************************************************************
* MAKROS
******************************************************************************/
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
/****************************************************************************** /******************************************************************************
* DEFINES * DEFINES
@ -20,8 +23,7 @@
/****************************************************************************** /******************************************************************************
* LOCAL VARIABLES * LOCAL VARIABLES
******************************************************************************/ ******************************************************************************/
Adafruit_NeoPixel* pPixelFan = NULL; Adafruit_NeoPixel pixels(MAX(WS2812SINGLE_LEDS, WS2812STRIP_GPIO_PIN), 0, NEO_RGB + NEO_KHZ800);
Adafruit_NeoPixel* pPixel = NULL;
OneWire oneWire(GPIO_DS18B20); OneWire oneWire(GPIO_DS18B20);
DallasTemperature sensors(&oneWire); DallasTemperature sensors(&oneWire);
@ -38,13 +40,13 @@ void setup() {
pinMode(SIGNAL_PIN, INPUT); pinMode(SIGNAL_PIN, INPUT);
pPixelFan = new Adafruit_NeoPixel(WS2812_LEDS1, GPIO_WS2812_PIN1, NEO_RGB + NEO_KHZ800); pixels.setPin(WS2812SINGLE_GPIO_PIN);
pixels.begin();
pixels.clear();
pixels.setBrightness(100);
pixels.fill(pixels.Color(255,0,0));
pixels.show();
pPixelFan->begin();
pPixelFan->clear();
pPixelFan->fill(pPixelFan->Color(255,0,0));
pPixelFan->setBrightness(100);
pPixelFan->show();
/* Initialize Temperature sensor */ /* Initialize Temperature sensor */
sensors.begin(); sensors.begin();
@ -54,6 +56,10 @@ void setup() {
sensors.begin(); sensors.begin();
Serial.println("Reset 1-Wire Bus"); Serial.println("Reset 1-Wire Bus");
} }
pixels.fill(pixels.Color(0,255,0));
pixels.setBrightness(50);
pixels.show();
} }
/** /**
@ -117,9 +123,12 @@ void loop() {
fanSpeedPercent = (100 - MIN_FAN_SPEED_PERCENT) * (temp - MIN_TEMP) / (MAX_TEMP - MIN_TEMP) + MIN_FAN_SPEED_PERCENT; fanSpeedPercent = (100 - MIN_FAN_SPEED_PERCENT) * (temp - MIN_TEMP) / (MAX_TEMP - MIN_TEMP) + MIN_FAN_SPEED_PERCENT;
} }
pPixelFan->fill(pPixelFan->Color(0,255,0)); pixels.setPin(WS2812STRIP_GPIO_PIN);
pPixelFan->setBrightness(fanSpeedPercent); pixels.begin();
pPixelFan->show(); pixels.clear();
pixels.fill(pixels.Color(0,255,0));
pixels.setBrightness(fanSpeedPercent);
pixels.show();
Serial.print(fanSpeedPercent); Serial.print(fanSpeedPercent);
Serial.print("%;"); Serial.print("%;");