Neopixel background LED option (#14025)

This commit is contained in:
Bob Kuhn
2019-05-18 02:36:37 -05:00
committed by Scott Lahteine
parent 84ac5b360b
commit 1dad6e754b
100 changed files with 423 additions and 6 deletions

View File

@ -2089,6 +2089,10 @@
#define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once.
#define NEOPIXEL_BRIGHTNESS 127 // Initial brightness (0-255)
//#define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup
// Use a single Neopixel LED for static (background) lighting
//#define NEOPIXEL_BKGD_LED_INDEX 0 // Index of the LED to use
//#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
#endif
/**

View File

@ -89,6 +89,9 @@ void LEDLights::set_color(const LEDColor &incol
: pixels.Color(incol.r, incol.g, incol.b, incol.w);
static uint16_t nextLed = 0;
#ifdef NEOPIXEL_BKGD_LED_INDEX
if (NEOPIXEL_BKGD_LED_INDEX == nextLed) { nextLed++; return; }
#endif
pixels.setBrightness(incol.i);
if (!isSequence)
set_neopixel_color(neocolor);

View File

@ -37,11 +37,29 @@
Adafruit_NeoPixel pixels(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800);
void set_neopixel_color(const uint32_t color) {
for (uint16_t i = 0; i < pixels.numPixels(); ++i) {
#ifdef NEOPIXEL_BKGD_LED_INDEX
if (NEOPIXEL_BKGD_LED_INDEX == i) i++;
#endif
pixels.setPixelColor(i, color);
}
pixels.show();
}
void set_neopixel_color_startup(const uint32_t color) {
for (uint16_t i = 0; i < pixels.numPixels(); ++i)
pixels.setPixelColor(i, color);
pixels.show();
}
#ifdef NEOPIXEL_BKGD_LED_INDEX
void set_neopixel_color_background() {
uint8_t background_color[4] = NEOPIXEL_BKGD_COLOR;
pixels.setPixelColor(NEOPIXEL_BKGD_LED_INDEX, pixels.Color(background_color[0], background_color[1], background_color[2], background_color[3]));
pixels.show();
}
#endif
void setup_neopixel() {
SET_OUTPUT(NEOPIXEL_PIN);
pixels.setBrightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
@ -50,14 +68,18 @@ void setup_neopixel() {
#if ENABLED(NEOPIXEL_STARTUP_TEST)
safe_delay(1000);
set_neopixel_color(pixels.Color(255, 0, 0, 0)); // red
set_neopixel_color_startup(pixels.Color(255, 0, 0, 0)); // red
safe_delay(1000);
set_neopixel_color(pixels.Color(0, 255, 0, 0)); // green
set_neopixel_color_startup(pixels.Color(0, 255, 0, 0)); // green
safe_delay(1000);
set_neopixel_color(pixels.Color(0, 0, 255, 0)); // blue
set_neopixel_color_startup(pixels.Color(0, 0, 255, 0)); // blue
safe_delay(1000);
#endif
#ifdef NEOPIXEL_BKGD_LED_INDEX
set_neopixel_color_background();
#endif
#if ENABLED(LED_USER_PRESET_STARTUP)
set_neopixel_color(pixels.Color(LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, LED_USER_PRESET_WHITE));
#else