LED’s wiping out when using functions
Hey guys,
I have made quite a long piece of code, and in short I have bluetooth. I tell bluetooth what to do and the corresponding signal has an action.
With this particular problem, I have tried the code in isolation and it works. See here (https://gist.github.com/Tejkaran/adbaac52a5063c0d22ced1dabe8ef3e0)
In short, it lights up the strip one LED at a time, and then once every one is lit up, the strip restarts.
However, in the larger piece I am doing it is not working properly. What happens is that once it has done one iteration of the lights, it does not keep the end light turned on, and instead turns it off, so the animation is in ruined and looks odd.
Here are the relevant parts of code (https://gist.github.com/Tejkaran/55bae56be412ef94577cc073aade586e)
has anyone experienced this before?
This is no only happening on this animation, but also on others on this piece and I dont understand why. there is another pattern I do where the lights slowly change from one end of the strip to the other, and then it cuts all the lights and then begins again. It is i really odd and I really do not understand it.
Help appreciated.
Reluctant to post the whole code but if it is necessary I will do so.
So first of all some basics :
-
Get rid of every single “delay(xxx)”. In your example it takes basically 3500+25*NUM_LEDS ms until your Bluetooth signal will be processed. Use the procedure from the blink without delay example or, even simpler, the EVERY_N_MILLISECONDS function from FastLED
-
Get rid of the second http://FastLED.show() in your first for loop. It’s simply useless.
-
Instead of writing http://FastLED.clear() and then http://FastLED.show() just write http://FastLED.clear(true) and that’s it.
Next step :
I have the impression that the problem is somewhere hidden in the rest of your code. Maybe in the rest of the Bluetooth code. My guess is,as soon as you introduce my suggested modifications (using non blocking code), nothing from the animation will work. Not because the animation is bad, but because something else in the code will corrupt your animation.
@Sven_Eric_Nielsen
1 - I understand hwo to do blink without delay, but what affect would that have on this? Whether or not it is ideal code, I do not see why it should cause such an issue. Could you expand upon this to help me understand please
2 - agreed, not sure how that got in there
3 - did not know that, thanks
next step
Will do, but just need an understanding first as mention in (1)
thank you
@Tejkaran_Samra
Well, I could repeat what I wrote, but I’m too lazy.
I wrote already the expected effect which would give you an indication where the problem is. Beside the fact that there is simply no reason to use the bad delay(xxx) solution the reason that you could identify the problem this way should be enough motivation to try it the right way.
@Sven_Eric_Nielsen
I understand what you are saying, that the bluetooth information will not be able to get through whilst there is a delay. I never really thought about it before. I am going through and amending as many things to as you suggested, that I am able to do so.
However, in this particular animation, I need a ‘for’ loop, and in that ‘for’ loop I need a delay[of sorts]. Is it best to keep a delay, or is there something else I can do, because if I do the dealy like in the blinkwithoutdelay, then the ‘for’ loop just does the iterations with no product because it is too quick
here is what i have now:
It did work with this, so it seems to be the right thing, though I still don’t understand what has changed i.e. in no way have I said to wipe the colour from the lights, now or before. I don’t really see why the bluetooth would affect it,
there is still more to do, so I hope you don’t mind me getting back to you when I have that done
@Sven_Eric_Nielsen
@Daniel_Garcia I have tagged you in this because I have been a fond user of FastLED site. I have spent a lot of time on this project and I think it is good, and thus, to return something to the users of FastLED I want to publish this to to the site, maybe someone will find it useful.
I have been through all of my code, and I was going to paste it to the site, but I thought it may be better to ask you guys, who are a lot more proficient in coding than myslef, to have a look, so the best possible code can go to the public.
This is the full code (https://gist.github.com/Tejkaran/f8496884dfa880a6f3e41b96a22d1d47)
The quick overview of how it runs to help you understand.
I have an app, if you so choose to you can try it (https://itunes.apple.com/us/app/led-light-strip-controller/id1227009286?mt=8) It is set at 0.99p/0.99c
the app sends a bluetooth signal which is picked up by HM-10 bluetooth
the signals sent are:
40 followed by 50/55 for motion sensor usage(50 for not using)
40 followed by 60->69 if an animation is chosen
10/20/30 if it is H/S/V slider being changed followed by x
i have also added a timed area, so if the motion sensor is on, and it is daytime, the lights will not turn on.
The second part is patterns/animations (In the app they are called patterns but I need to change this to animations as it sounds better. In the code it is called animations)
from there i have made animations for each one, the animations are as follows:
pattern 1 - slowly crawling along strip rainbow colours
pattern 2 - faster crawling along strip rainbow colours
pattern 3 - slow whole strip changing colour
pattern 4 - fast whole strip changing colour
pattern 5 - snake esque light 10 pixels long
pattern 6 - custom palette (colour and then gap)
pattern 7 - cloud colours cusom palette
pattern 8 - a third palette which i extracted using palette knife
pattern 9 - a bouncing red light
pattern 10 - middle out light up changing colours