1
0

fix off-by-one bug in fadeStripColor

This commit is contained in:
Gottfried Mayer 2023-01-19 19:48:28 +01:00
parent 5dc966c010
commit 742341c01f
3 changed files with 11 additions and 12 deletions

View File

@ -1,9 +1,8 @@
// User configuration // User configuration
#ifndef nightlightConfig_h #pragma once
#define nightlightConfig_h
#define NIGHTLIGHT_VERSION "1.0" #define NIGHTLIGHT_VERSION "1.3"
// wifi stuff // wifi stuff
#define WIFI_CONFIGURED 3 #define WIFI_CONFIGURED 3
@ -24,5 +23,3 @@
// serial debug enabled (comment out to disable) // serial debug enabled (comment out to disable)
#define SERIAL_DEBUG #define SERIAL_DEBUG
#endif

View File

@ -15,12 +15,12 @@ struct gRGB
}; };
/// allow construction from R, G, B /// allow construction from R, G, B
inline gRGB(uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline)) inline gRGB(uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline))
: r(ir), g(ig), b(ib) : r(ir), g(ig), b(ib)
{ {
} }
/// allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code /// allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code
inline gRGB(uint32_t colorcode) __attribute__((always_inline)) inline gRGB(uint32_t colorcode) __attribute__((always_inline))
: r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF) : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF)
{ {
} }
}; };
@ -44,7 +44,7 @@ uint8_t blend8(uint8_t a, uint8_t b, uint8_t amountOfB)
return result; return result;
} }
void setStripColor(Adafruit_NeoPixel* strip, uint32_t color) void setStripColor(Adafruit_NeoPixel *strip, uint32_t color)
{ {
for (int i = 0; i < strip->numPixels(); i++) for (int i = 0; i < strip->numPixels(); i++)
{ {
@ -53,7 +53,7 @@ void setStripColor(Adafruit_NeoPixel* strip, uint32_t color)
strip->show(); strip->show();
} }
void fadeStripColor(Adafruit_NeoPixel* strip, gRGB prev, gRGB next) void fadeStripColor(Adafruit_NeoPixel *strip, gRGB prev, gRGB next)
{ {
gRGB curr = prev; gRGB curr = prev;
uint8_t fadeSteps = 100; uint8_t fadeSteps = 100;
@ -68,13 +68,15 @@ void fadeStripColor(Adafruit_NeoPixel* strip, gRGB prev, gRGB next)
setStripColor(strip, cColor(curr.r, curr.g, curr.b)); setStripColor(strip, cColor(curr.r, curr.g, curr.b));
delay(delayTime); delay(delayTime);
} }
curr = next;
setStripColor(strip, cColor(curr.r, curr.g, curr.b));
} }
void setFirstPixelTemporary(Adafruit_NeoPixel* strip, uint32_t color, uint16_t time) void setFirstPixelTemporary(Adafruit_NeoPixel *strip, uint32_t color, uint16_t time)
{ {
strip->setPixelColor(0, color); strip->setPixelColor(0, color);
strip->show(); strip->show();
delay(time); delay(time);
strip->setPixelColor(0, strip->getPixelColor(1)); strip->setPixelColor(0, strip->getPixelColor(1));
strip->show(); strip->show();
} }

View File

@ -277,4 +277,4 @@ void loop()
} }
delay(100); delay(100);
} }