fix things for two leds at same position
This commit is contained in:
parent
968507ad7b
commit
bcfc1bcd4d
|
@ -132,9 +132,9 @@ void NeoPatterns::RainbowCycle(uint8_t interval, direction dir) {
|
||||||
|
|
||||||
void NeoPatterns::RainbowCycleUpdate()
|
void NeoPatterns::RainbowCycleUpdate()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numPixels(); i++)
|
for (int i = 0; i < NUMDOTS; i++)
|
||||||
{
|
{
|
||||||
setPixelColor(i, Wheel(((i * 256 / numPixels()) + Index) & 255));
|
setPixelColorMapped(i, Wheel(((i * 256 / NUMDOTS) + Index) & 255));
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
Increment();
|
Increment();
|
||||||
|
@ -143,22 +143,22 @@ void NeoPatterns::RainbowCycleUpdate()
|
||||||
void NeoPatterns::TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction dir) {
|
void NeoPatterns::TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction dir) {
|
||||||
ActivePattern = THEATER_CHASE;
|
ActivePattern = THEATER_CHASE;
|
||||||
Interval = interval;
|
Interval = interval;
|
||||||
TotalSteps = numPixels();
|
TotalSteps = NUMDOTS;
|
||||||
Color1 = color1;
|
Color1 = color1;
|
||||||
Color2 = color2;
|
Color2 = color2;
|
||||||
Index = 0;
|
Index = 0;
|
||||||
Direction = dir;
|
Direction = dir;
|
||||||
}
|
}
|
||||||
void NeoPatterns::TheaterChaseUpdate() {
|
void NeoPatterns::TheaterChaseUpdate() {
|
||||||
for (int i = 0; i < numPixels(); i++)
|
for (int i = 0; i < NUMDOTS; i++)
|
||||||
{
|
{
|
||||||
if ((i + Index) % 3 == 0)
|
if ((i + Index) % 3 == 0)
|
||||||
{
|
{
|
||||||
setPixelColor(i, Color1);
|
setPixelColorMapped(i, Color1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setPixelColor(i, Color2);
|
setPixelColorMapped(i, Color2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
|
@ -169,7 +169,7 @@ void NeoPatterns::ColorWipe(uint32_t color, uint8_t interval, direction dir)
|
||||||
{
|
{
|
||||||
ActivePattern = COLOR_WIPE;
|
ActivePattern = COLOR_WIPE;
|
||||||
Interval = interval;
|
Interval = interval;
|
||||||
TotalSteps = numPixels();
|
TotalSteps = NUMDOTS;
|
||||||
Color1 = color;
|
Color1 = color;
|
||||||
Index = 0;
|
Index = 0;
|
||||||
Direction = dir;
|
Direction = dir;
|
||||||
|
@ -178,7 +178,7 @@ void NeoPatterns::ColorWipe(uint32_t color, uint8_t interval, direction dir)
|
||||||
// Update the Color Wipe Pattern
|
// Update the Color Wipe Pattern
|
||||||
void NeoPatterns::ColorWipeUpdate()
|
void NeoPatterns::ColorWipeUpdate()
|
||||||
{
|
{
|
||||||
setPixelColor(Index, Color1);
|
setPixelColorMapped(Index, Color1);
|
||||||
show();
|
show();
|
||||||
Increment();
|
Increment();
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ void NeoPatterns::Scanner(uint32_t color1, uint8_t interval, bool colorful, bool
|
||||||
{
|
{
|
||||||
ActivePattern = SCANNER;
|
ActivePattern = SCANNER;
|
||||||
Interval = interval;
|
Interval = interval;
|
||||||
TotalSteps = (numPixels() - 1) * 2;
|
TotalSteps = (NUMDOTS - 1) * 2;
|
||||||
Color1 = color1;
|
Color1 = color1;
|
||||||
Index = 0;
|
Index = 0;
|
||||||
wPos = 0;
|
wPos = 0;
|
||||||
|
@ -208,7 +208,7 @@ void NeoPatterns::ScannerUpdate()
|
||||||
wPos++;
|
wPos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < numPixels(); i++)
|
for (int i = 0; i < NUMDOTS; i++)
|
||||||
{
|
{
|
||||||
int finalpos;
|
int finalpos;
|
||||||
if (spiral) {
|
if (spiral) {
|
||||||
|
@ -220,15 +220,15 @@ void NeoPatterns::ScannerUpdate()
|
||||||
}
|
}
|
||||||
if (i == Index) // Scan Pixel to the right
|
if (i == Index) // Scan Pixel to the right
|
||||||
{
|
{
|
||||||
setPixelColor(finalpos, Color1);
|
setPixelColorMapped(finalpos, Color1);
|
||||||
}
|
}
|
||||||
else if (i == TotalSteps - Index) // Scan Pixel to the left
|
else if (i == TotalSteps - Index) // Scan Pixel to the left
|
||||||
{
|
{
|
||||||
setPixelColor(finalpos, Color1);
|
setPixelColorMapped(finalpos, Color1);
|
||||||
}
|
}
|
||||||
else // Fading tail
|
else // Fading tail
|
||||||
{
|
{
|
||||||
setPixelColor(finalpos, DimColor(getPixelColor(finalpos)));
|
setPixelColorMapped(finalpos, DimColor(getPixelColorMapped(finalpos)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
|
@ -283,9 +283,9 @@ void NeoPatterns::RandomFadeSingle(uint8_t interval, uint8_t speed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeoPatterns::RandomFadeSingleUpdate() {
|
void NeoPatterns::RandomFadeSingleUpdate() {
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
for (int i = 0; i < NUMDOTS; i++) {
|
||||||
pixelR_buffer[i] += random(0, random(0, WheelSpeed + 1) + 1); //use buffer red channel for color wheel
|
pixelR_buffer[i] += random(0, random(0, WheelSpeed + 1) + 1); //use buffer red channel for color wheel
|
||||||
setPixelColor(i, Wheel(pixelR_buffer[i]));
|
setPixelColorMapped(i, Wheel(pixelR_buffer[i]));
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
Increment();
|
Increment();
|
||||||
|
@ -293,7 +293,7 @@ void NeoPatterns::RandomFadeSingleUpdate() {
|
||||||
|
|
||||||
void NeoPatterns::RandomBuffer()
|
void NeoPatterns::RandomBuffer()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
for (int i = 0; i < NUMDOTS; i++) {
|
||||||
uint32_t c = Wheel(random(0, 256));
|
uint32_t c = Wheel(random(0, 256));
|
||||||
pixelR_buffer[i] = (uint8_t)(c >> 16);
|
pixelR_buffer[i] = (uint8_t)(c >> 16);
|
||||||
pixelG_buffer[i] = (uint8_t)(c >> 8);
|
pixelG_buffer[i] = (uint8_t)(c >> 8);
|
||||||
|
@ -305,8 +305,8 @@ void NeoPatterns::Random()
|
||||||
{
|
{
|
||||||
None(); // Stop all other effects
|
None(); // Stop all other effects
|
||||||
ActivePattern = RANDOM;
|
ActivePattern = RANDOM;
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
for (uint8_t i = 0; i < NUMDOTS; i++) {
|
||||||
setPixelColor(i, Wheel(random(0, 256)));
|
setPixelColorMapped(i, Wheel(random(0, 256)));
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,7 @@ void NeoPatterns::Smooth(uint8_t wheelSpeed, uint8_t smoothing, uint8_t strength
|
||||||
movingPoint_x = 3;
|
movingPoint_x = 3;
|
||||||
movingPoint_y = 3;
|
movingPoint_y = 3;
|
||||||
// Clear buffer (from previous or different effects)
|
// Clear buffer (from previous or different effects)
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
for (int i = 0; i < NUMDOTS; i++) {
|
||||||
pixelR_buffer[i] = 0;
|
pixelR_buffer[i] = 0;
|
||||||
pixelG_buffer[i] = 0;
|
pixelG_buffer[i] = 0;
|
||||||
pixelB_buffer[i] = 0;
|
pixelB_buffer[i] = 0;
|
||||||
|
@ -401,18 +401,18 @@ void NeoPatterns::SmoothUpdate() {
|
||||||
movingPoint_x = startx;
|
movingPoint_x = startx;
|
||||||
movingPoint_y = starty;
|
movingPoint_y = starty;
|
||||||
|
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
for (int i = 0; i < NUMDOTS; i++) {
|
||||||
pixelR_buffer[i] = (Smoothing / 100.0) * pixelR[i] + (1.0 - (Smoothing / 100.0)) * getAverage(pixelR, i, 0, 0);
|
pixelR_buffer[i] = (Smoothing / 100.0) * pixelR[i] + (1.0 - (Smoothing / 100.0)) * getAverage(pixelR, i, 0, 0);
|
||||||
pixelG_buffer[i] = (Smoothing / 100.0) * pixelG[i] + (1.0 - (Smoothing / 100.0)) * getAverage(pixelG, i, 0, 0);
|
pixelG_buffer[i] = (Smoothing / 100.0) * pixelG[i] + (1.0 - (Smoothing / 100.0)) * getAverage(pixelG, i, 0, 0);
|
||||||
pixelB_buffer[i] = (Smoothing / 100.0) * pixelB[i] + (1.0 - (Smoothing / 100.0)) * getAverage(pixelB, i, 0, 0);
|
pixelB_buffer[i] = (Smoothing / 100.0) * pixelB[i] + (1.0 - (Smoothing / 100.0)) * getAverage(pixelB, i, 0, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
for (int i = 0; i < NUMDOTS; i++) {
|
||||||
pixelR[i] = pixelR_buffer[i];
|
pixelR[i] = pixelR_buffer[i];
|
||||||
pixelG[i] = pixelG_buffer[i];
|
pixelG[i] = pixelG_buffer[i];
|
||||||
pixelB[i] = pixelB_buffer[i];
|
pixelB[i] = pixelB_buffer[i];
|
||||||
setPixelColor(i, pixelR[i], pixelG[i], pixelB[i]);
|
setPixelColorMapped(i, Color(pixelR[i], pixelG[i], pixelB[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
show();
|
show();
|
||||||
|
@ -444,17 +444,17 @@ void NeoPatterns::Icon(uint8_t fontchar, String iconcolor, uint8_t interval)
|
||||||
|
|
||||||
void NeoPatterns::IconUpdate()
|
void NeoPatterns::IconUpdate()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
for (int i = 0; i < NUMDOTS; i++) {
|
||||||
uint64_t mask = 1LL << (uint64_t)i;
|
uint64_t mask = 1LL << (uint64_t)i;
|
||||||
|
|
||||||
if ( (font[FontChar]&mask) == 0) {
|
if ( (font[FontChar]&mask) == 0) {
|
||||||
setPixelColor(numToPos(i), Color(0, 0, 0)); //bit is 0 at pos i
|
setPixelColorMapped(numToPos(i), Color(0, 0, 0)); //bit is 0 at pos i
|
||||||
} else {
|
} else {
|
||||||
float _brightness = 1.0 - ( (TotalSteps - Index) * 1.0 / TotalSteps );
|
float _brightness = 1.0 - ( (TotalSteps - Index) * 1.0 / TotalSteps );
|
||||||
uint8_t _r = (uint8_t)(Color1 >> 16);
|
uint8_t _r = (uint8_t)(Color1 >> 16);
|
||||||
uint8_t _g = (uint8_t)(Color1 >> 8);
|
uint8_t _g = (uint8_t)(Color1 >> 8);
|
||||||
uint8_t _b = (uint8_t)Color1;
|
uint8_t _b = (uint8_t)Color1;
|
||||||
setPixelColor(numToPos(i), Color(_r * _brightness, _g * _brightness, _b * _brightness)); //bit is 1 at pos i
|
setPixelColorMapped(numToPos(i), Color(_r * _brightness, _g * _brightness, _b * _brightness)); //bit is 1 at pos i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
|
@ -532,9 +532,9 @@ void NeoPatterns::PlasmaUpdate()
|
||||||
color_4 *= color_4;
|
color_4 *= color_4;
|
||||||
|
|
||||||
// Scale the color up to 0..7 . Max brightness is 7.
|
// Scale the color up to 0..7 . Max brightness is 7.
|
||||||
//strip.setPixelColor(col + (edge * row), strip.Color(color_4, 0, 0) );
|
//strip.setPixelColorMapped(col + (edge * row), strip.Color(color_4, 0, 0) );
|
||||||
|
|
||||||
setPixelColor(xyToPos(row, col), Color(color_1, color_2, color_3));
|
setPixelColorMapped(xyToPos(row, col), Color(color_1, color_2, color_3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
|
@ -561,9 +561,9 @@ uint32_t NeoPatterns::DimColor(uint32_t color)
|
||||||
// Set all pixels to a color (synchronously)
|
// Set all pixels to a color (synchronously)
|
||||||
void NeoPatterns::ColorSet(uint32_t color)
|
void NeoPatterns::ColorSet(uint32_t color)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < numPixels(); i++)
|
for (int i = 0; i < NUMDOTS; i++)
|
||||||
{
|
{
|
||||||
setPixelColor(i, color);
|
setPixelColorMapped(i, color);
|
||||||
}
|
}
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
@ -615,18 +615,32 @@ uint32_t NeoPatterns::Wheel(byte WheelPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert x y pixel position to matrix position
|
// Convert x y pixel position to matrix position
|
||||||
uint8_t NeoPatterns::xyToPos(int x, int y) {
|
#ifdef LEDBOX3X6
|
||||||
|
uint8_t ledbox3x6_mapping[6][3] = {
|
||||||
|
{0,1,2},
|
||||||
|
{5,4,3},
|
||||||
|
{6,7,8},
|
||||||
|
{15,14,9},
|
||||||
|
{16,13,10},
|
||||||
|
{17,12,11}
|
||||||
|
};
|
||||||
|
uint8_t NeoPatterns::xyToPos(int x, int y) {
|
||||||
|
return ledbox3x6_mapping[x][y];
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
uint8_t NeoPatterns::xyToPos(int x, int y) {
|
||||||
if (y % 2 == 0) {
|
if (y % 2 == 0) {
|
||||||
return (y * WIDTH + x);
|
return (y * WIDTH + x);
|
||||||
} else {
|
} else {
|
||||||
return (y * WIDTH + (WIDTH-1 - x));
|
return (y * WIDTH + (WIDTH-1 - x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//convert pixel number to actual 8x8 matrix position
|
//convert pixel number to actual 8x8 matrix position
|
||||||
uint8_t NeoPatterns::numToPos(int num) {
|
uint8_t NeoPatterns::numToPos(int num) {
|
||||||
int x = num % 8;
|
int x = num % WIDTH;
|
||||||
int y = num / 8;
|
int y = num / HEIGHT;
|
||||||
return xyToPos(x, y);
|
return xyToPos(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,5 +728,21 @@ uint32_t NeoPatterns::parseColor(String value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NeoPatterns::setPixelColorMapped(uint8_t i, uint32_t c){
|
||||||
|
#ifdef LEDBOX3X6
|
||||||
|
setPixelColor(i*2,c);
|
||||||
|
setPixelColor(i*2+1,c);
|
||||||
|
#else
|
||||||
|
setPixelColor(i,c);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
uint32_t NeoPatterns::getPixelColorMapped(uint8_t i){
|
||||||
|
|
||||||
|
#ifdef LEDBOX3X6
|
||||||
|
return getPixelColor(i*2);
|
||||||
|
#else
|
||||||
|
return getPixelColor(i);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ class NeoPatterns : public Adafruit_NeoPixel
|
||||||
uint8_t numToPos(int num);
|
uint8_t numToPos(int num);
|
||||||
uint8_t getAverage(uint8_t array[], uint8_t i, int x, int y);
|
uint8_t getAverage(uint8_t array[], uint8_t i, int x, int y);
|
||||||
uint32_t parseColor(String value);
|
uint32_t parseColor(String value);
|
||||||
|
void setPixelColorMapped(uint8_t i, uint32_t c);
|
||||||
|
uint32_t getPixelColorMapped(uint8_t i);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Member Variables:
|
// Member Variables:
|
||||||
|
|
|
@ -1,16 +1,27 @@
|
||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//8x8 Matrix
|
//8x8 Matrix
|
||||||
/*
|
|
||||||
|
#define HOSTNAME "pixelprojektor"
|
||||||
|
#define NODENAME "pixel"
|
||||||
#define WIDTH 8 //WIDTH is along consecutive pixels
|
#define WIDTH 8 //WIDTH is along consecutive pixels
|
||||||
#define HEIGHT 8
|
#define HEIGHT 8
|
||||||
#define NUMPIXELS 64 // 8x8 Matrix
|
#define NUMPIXELS 64 // 8x8 Matrix
|
||||||
*/
|
#define NUMDOTS numPixels() //dots equals num pixels
|
||||||
|
|
||||||
|
|
||||||
//3x6 LED Box
|
//3x6 LED Box
|
||||||
|
/*
|
||||||
|
#define HOSTNAME "ledbox"
|
||||||
|
#define NODENAME "pixel"
|
||||||
|
#define LEDBOX3X6
|
||||||
#define WIDTH 3
|
#define WIDTH 3
|
||||||
#define HEIGHT 6
|
#define HEIGHT 6
|
||||||
#define NUMPIXELS 18 // 3x6 LED Box
|
#define NUMPIXELS 36 // 3x6 LED Box, 2pixels per box
|
||||||
|
#define NUMDOTS 18
|
||||||
|
*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,7 +25,7 @@ void StripComplete() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HomieNode homieNode("pixel", "commands");
|
HomieNode homieNode(NODENAME, "commands");
|
||||||
|
|
||||||
|
|
||||||
bool onSetColor(const HomieRange& range, const String& value) {
|
bool onSetColor(const HomieRange& range, const String& value) {
|
||||||
|
@ -191,7 +191,7 @@ void loopHandler() {
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
Homie_setFirmware("pixelprojektor", "1.0.0");
|
Homie_setFirmware(HOSTNAME, "1.0.0");
|
||||||
Homie.setLoopFunction(loopHandler);
|
Homie.setLoopFunction(loopHandler);
|
||||||
|
|
||||||
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
|
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
|
||||||
|
@ -208,13 +208,14 @@ void setup() {
|
||||||
strip.begin();
|
strip.begin();
|
||||||
strip.clear();
|
strip.clear();
|
||||||
// strip.setBrightness(64);
|
// strip.setBrightness(64);
|
||||||
// strip.setBrightness(255); // HEEELLLLLLL :)
|
strip.setBrightness(255); // HEEELLLLLLL :)
|
||||||
strip.setBrightness(10); // DEBUG!
|
//strip.setBrightness(10); // DEBUG!
|
||||||
strip.show();
|
strip.show();
|
||||||
stopAfterCompletion = false; // Default
|
stopAfterCompletion = false; // Default
|
||||||
// strip.Plasma(); // Default effect
|
//strip.Plasma(); // Default effect
|
||||||
|
strip.RainbowCycle(50);
|
||||||
|
|
||||||
ArduinoOTA.setHostname("pixelprojektor");
|
ArduinoOTA.setHostname(HOSTNAME);
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
strip.clear();
|
strip.clear();
|
||||||
strip.setBrightness(64);
|
strip.setBrightness(64);
|
||||||
|
|
Loading…
Reference in New Issue