So - I wanted a rainbow scroller for a window display.
I did a 5 metre (300) WS2812 led scroller - which looked very pretty (using a Nano)
But - could I get a Attiny to do the same? So here is a Rainbow scroller using an ATTINY85 (running at 16MHz)- the trick I use is to generate the colours on the fly rather than using a buffer (which for the 5m display is 900bytes)
Here presented as a 60 led scroller (note that I buffer the colours for the rainbow as 'wheel' took a little too long (although at 19us it was less than the 50us reset time for the LED strip)
This doesn't use the WS2812 component and has my own 'bit-bang' output to pin B0.
It's also a 'request' for the callback feature in V9 - as the colours are generated as required it would make outputting different patterns very easy - just by changing the 'generator' function called...
Martin
WS2812 Christmas Fun
-
- Valued Contributor
- Posts: 991
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
-
- Valued Contributor
- Posts: 991
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
Re: WS2812 Christmas Fun
In fact callback functions turn out to be easy to work with anyway.
(Perhaps this should be in tricks and tips?)
In supplementary code I defined my function pointer as ;
- as in this case I want a function takes an 'offset' (int) and returns a 32 bit number (actually a 24 bit colour)
Then to set the generator function in a C block :
Where Pattern2 is the Flowcode macro to call...
And to call (also in a C block)
My 'test' program has two patterns (a red green stripey and a rainbow scroll) - but now it is easy to add extra patterns.
Note that if we really wanted to get 'fancy' we could store function pointers in an array and then work through the array rather than using the individual assignments I have here...
Martin
Perhaps I'll try a 'KITT' scroller next...
(Perhaps this should be in tricks and tips?)
In supplementary code I defined my function pointer as ;
Code: Select all
MX_UINT32 (*Generator)(int);
Then to set the generator function in a C block :
Code: Select all
Generator = FCM_Pattern2;
And to call (also in a C block)
Code: Select all
FCL_DATA = Generator(FCL_N);
Note that if we really wanted to get 'fancy' we could store function pointers in an array and then work through the array rather than using the individual assignments I have here...
Martin
Perhaps I'll try a 'KITT' scroller next...
-
- Valued Contributor
- Posts: 991
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
Re: WS2812 Christmas Fun
As an aside - I did the timings for the WS2812 instructions using a smartscope to check the times.
They are currently reduced to 149euros on the Elektor website. I recommend it - a very useful bit of kit. An oscilloscope that works with PC (any flavour), smartphone or tablet
(and, sadly, I'm not on commission)
Martin
They are currently reduced to 149euros on the Elektor website. I recommend it - a very useful bit of kit. An oscilloscope that works with PC (any flavour), smartphone or tablet
(and, sadly, I'm not on commission)
Martin