thebigpotatoe / Super-Simple-RGB-WiFi-Lamp

A project based on the ESP8266 and WS2812b
MIT License
66 stars 28 forks source link

Fadetoblack gives one extra full light glimp #3

Closed StefaanVanDooren closed 4 years ago

StefaanVanDooren commented 4 years ago

Describe the bug

Whenever I turn off a mode, it fades to off nicely, and then turns on again for a second or so.

To Reproduce Steps to reproduce the behavior:

  1. Go to whatever mode
  2. Click on "Off"
  3. Watch the lamp fade and go on again briefly

Expected behavior Fade off and stay off

thebigpotatoe commented 4 years ago

Ill have a dig into this, haven't seen it happen but will try to recreate.

StefaanVanDooren commented 4 years ago

It only happens when turning the lamp off. When switching modes, it fades to black and then comes on again with the right mode. I put a little video online : https://drive.google.com/file/d/11H5b7lDtVfai7jVCG0KzLAqhSe5cue0E/view?usp=sharing

PS: be sure to download the video, when I play it in my browser it's barely visible.

thebigpotatoe commented 4 years ago

Had to watch it a few times but i think i see what you mean (very evident when downloaded though). Might be an issue with wrap around in my code or fast LED. If you haven't, make sure you are up to date with the libraries in the meantime.

Awesome to see someone build it though.

StefaanVanDooren commented 4 years ago

be sure to download the video, when I play it in my browser it's barely visible.

It's a great little project. I would love to see something like a fire mode ....

StefaanVanDooren commented 4 years ago

I just noticed its not just when fading to black, it also happens when the lights are a full brightness. But then it's not that visible, because it switches directly back to full brightness. New video uploaded, again you have to download it to really see it.... around second 2

https://drive.google.com/open?id=13ciJeC-3PrgpXlDLq5uSqk3twDCW0LJo

StefaanVanDooren commented 4 years ago

New observation.... only happens with certain fade time... It does happen with 500, 1400, 1500, 1800 and 1900 but not with 0, 100, 200, 300, 400, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1500, 1600, 1700, 2000

thebigpotatoe commented 4 years ago

Awesome. Thanks for the updates. It does seem to happen for those numbers, just tested it then. I'll dig into the code as soon as I can and see where there is an error.

StefaanVanDooren commented 4 years ago

I added some debugging to the code, and noticed that modeChangeFadeAmount got below 0 for those certain Fadetimes. Adding a constrain seems to stop the behavior for me.

if (modeChangeFadeAmount > 0) { EVERY_N_MILLISECONDS(20) { modeChangeFadeAmount -= (FadeTime > 0) ? (255 / ((float)FadeTime/20)) : 255; modeChangeFadeAmount = constrain(modeChangeFadeAmount,0,255); Serial.print("[handleMode] - modeChaneFadeAmount : "); Serial.println(modeChangeFadeAmount); };

I added a constrain in all places where you change the modeChangeFadeAmount.

StefaanVanDooren commented 4 years ago

Looking a bit further, I found you have an "else" laying around before your constrain in the code. (LEDS.ino) commenting this one out, also fixes the issue....

else

// Globally Scale the brightness of all LED's modeChangeFadeAmount = constrain(modeChangeFadeAmount, 0, 255); nscale8(ledString, NUM_LEDS, (int)modeChangeFadeAmount);

thebigpotatoe commented 4 years ago

Found all of the above. Seemed to be summing one last time using the inbuilt fastLED function EVERY_N_MILLISECONDS for those times you stated.

Ended up just shuffling a few things around and now the integer does not overflow. Test and worked in the latest pull for myself, let me know if you have issues.

StefaanVanDooren commented 4 years ago

Working for me.

thebigpotatoe commented 4 years ago

Perfect, closing issue