Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change pixel number at run time #1

Closed
sticilface opened this issue May 6, 2015 · 8 comments
Closed

Change pixel number at run time #1

sticilface opened this issue May 6, 2015 · 8 comments

Comments

@sticilface
Copy link

Would be useful to be able to redefine the number of pixels, and the output pin.

The esp can be configured by web interface, so modules can be deployed then configured.

I tried adjusting the count by re-issuing the NeoPixelBus strip = NeoPixelBus(pixelCount, 8); (in the adafruit lib, not yours) but every time the loop circles it gets reset.

@Makuna
Copy link
Owner

Makuna commented May 6, 2015

The best way to handle this today is to dynamically create the NeoPixelBus rather than doing it statically. See below.

You would not be able to maintain pixel colors and not sure you would want to.

NeoPixelBus* pNeoPixels = NULL; // dynamic

setup()
{
    uint16_t countPixels = Eeprom.GetPixelCount(); // how ever you store them
    uint8_t pinPixels = Eeprom.GetPixelPin(); // how ever you store them
    ChangeNeoPixels(countPixels, pinPixels); // initial setup
}

loop()
{
...
}

// called to change the number of pixels
void ChangeNeoPixels(uint16_t count, uint8_t pin)
{
    if (pNeoPixels)
    {
        delete pNeoPixels;
    }
    pNeoPixels = new NeoPixelBus(count, pin);
    pNeoPixels->Begin();
}

@sticilface
Copy link
Author

Thank you.

Is that not able to maintain them when the number has been changed. But after it works as normal?

On 6 May 2015, at 16:32, Michael Miller [email protected] wrote:

The best way to handle this today is to dynamically create the NeoPixelBus rather than doing it statically. See below.

You would not be able to maintain pixel colors and not sure you would want to.

NeoPixelBus* pNeoPixels = NULL; // dynamic

setup()
{
uint16_t countPixels = Eeprom.GetPixelCount(); // how ever you store them
uint8_t pinPixels = Eeprom.GetPixelPin(); // how ever you store them
ChangeNeoPixels(countPixels, pinPixels); // initial setup
}

loop()
{
...
}

// called to change the number of pixels
void ChangeNeoPixels(uint16_t count, uint8_t pin)
{
if (pNeoPixels)
{
delete pNeoPixels;
}
pNeoPixels = new NeoPixelBus(count, pin);
}

Reply to this email directly or view it on GitHub.

@Makuna
Copy link
Owner

Makuna commented May 6, 2015

What does it mean when you change the number of pixels?
To me, this means its a completely different physical collection of LEDs, so maintaining the colors that are present doesn't logically make sense. What example do you have that you would want to maintain the colors?

In the example above, it will clear the internal state of the "new" collection of LEDs to black. Just call Show() and it will be applied to the physical LEDs.

@sticilface
Copy link
Author

We're talking about the same thing. And I agree you don't want that anyway. So we're in agreement.

I wanted to make sure that it didn't affect the function of the pixels.

Thanks

A

On 6 May 2015, at 18:01, Michael Miller [email protected] wrote:

What does it mean when you change the number of pixels?
To me, this means its a completely different physical collection of LEDs, so maintaining the colors that are present doesn't logically make sense. What example do you have that you would want to maintain the colors?

In the example above, it will clear the internal state of the "new" collection of LEDs to black. Just call Show() and it will be applied to the physical LEDs.


Reply to this email directly or view it on GitHub.

@sticilface
Copy link
Author

Worked very well. Thank you

@mariusmotea
Copy link

Hi,

I tried this option with the current version of the library and WS2812 board, but is not working.


NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(false);

void ChangeNeoPixels(uint16_t count)
{
    if (strip)
    {
        delete strip;
    }
    strip = new NeoPixelBus(count);
    strip->Begin();
}

the error is:

WS2812BHueStrip:577:17: error: expected type-specifier before 'NeoPixelBus'
     strip = new NeoPixelBus(count);
                 ^
WS2812BHueStrip:577:17: error: expected ';' before 'NeoPixelBus'
WS2812BHueStrip:578:10: error: base operand of '->' has non-pointer type 'NeoPixelBus<NeoGrbFeature, NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeedWs2812x> >'
     strip->Begin();
          ^
exit status 1
could not convert 'strip' from 'NeoPixelBus<NeoGrbFeature, NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeedWs2812x> >' to 'bool'

I try to create a ws2812 sketch that store configuration in SPIFS so the number of leds can be changed from web interface.

Thanks,
Marius.

@Makuna
Copy link
Owner

Makuna commented Feb 8, 2019

@mariusmotea commenting on a closed issue is not a good practice.

Please read this Wiki Topic on the subject of dynamic pixel counts.

@mariusmotea
Copy link

mariusmotea commented Feb 8, 2019

Thanks, i found that but it copile with errors. After i replace Strip with strip and strip.SetPixelColor with strip->SetPixelColor it compile but i did not test it to confirm.

AMoo-Miki pushed a commit to AMoo-Miki/NeoPixelBus that referenced this issue Dec 29, 2021
Update for ESP RTOS v3.2 era.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants