I'm having a complete brain fart.

I’m having a complete brain fart.

This year i built some large “snowflakes” for the front of the house.

I used strings of 12mm LEDs, and +Mark Kriegsman twinkle fox (2015) and they have looked great.

But i started thinking about animating the snowflakes by illuminating specific LEDs in sequence.

I’ve attached a diagram to make it a bit easier to illustrate.

If i illuminate each of the segments 1-5 in order, blacking out the previous segment, the effect for the viewer will be one of rotational movement.

I know which LEDs are in a segment, so i began by putting the LEDs into arrays.

uint8_t gSegment1[] = {1,2,3,4,5,6,7,8,9};
etc

then, i thought about putting each of those segments into a large array, then i can loop over that (and loop over the inner array that contains the LEDs to be lit):

uinut8_t gSements = [] { &gSegment1, &gSegment2, &gSegment3, &gSegment4, &gSegment5 etc etc

Herein lies the rub.

I get a GCC errors:

error: cannot convert ‘uint8_t ()[8] {aka unsigned char ()[8]}’ to ‘uint8_t {aka unsigned char*}’ in initialization

So i’m scratching my head, given its been 20+ years since i did anything useful with C on a daily basis, and my google foo hasn’t turned up anything, but i know i’m doing something stupid here (with regards pointers and references), but not sure what.

All help and or criticism gratefully accepted.

@Stuart_Taylor - Try this:

const unsigned char * gSegments[] = { gSegment1, gSegment2, gSegment3, gSegment4, etc etc};

I used this technique in my old sketch for an 8X8 NeoPixel panel at:

and can be seen:

It uses a lot of arrays of arrays. It is written with the NeoPixel library and I just finished rewriting it with the FastLED library and will post it soon on GitHub.

Looks like you are missing a ‘*’ to declare the gSegments variable as an array of pointers.

uint8_t *gSegments[] = { gSegment1, …};

@Ken_White ah, yes, how you have done it, is where i’m heading.

However I see that you have hard coded the size or your arrays:

for(uint16_t j=0; j<4; j++) {
uint16_t x=boxtotalarray[j];

I wanted to use sizeof()so that the function can work on any array size and not a fixed size, so that the parent array, could hold children arrays of varying length.

e.g an inner circle has less LEDs than an outer circle.

I think i’m getting the size of the pointer (address location of the array) and not the contents of the array.

Many thanks for your input, as you have validated that the concept (of using arrays within arrays) will work.

@Michael_Burg yes, that was a typo in my post, sorry.

how do i dereference to get the size of a child array?

uint8_t aSize = sizeof(gSegments) / sizeof(unit8_t); retruns the size of the parent ok, so i can use a for loop easily.

But if i then

for (uint8_t i = 0; i < aSize; i++)
{
gShapeIdx = gSegments[i];

i cant use sizeof() on gShapeIdx, because i think i’m asking for the sizeof the address??

Doh.

Worked it out.

created an array to hold the sizes (generated with sizeof()).

I’ll post a video and code when its complete.

But is now 23:55 and 2017 is 5 minutes away.

Happy New year FastLEDers!!

@Stuart_Taylor I look forward to seeing your code as I’m trying to do something similar for a “daft-punk coffee table” type animation.

As I couldn’t figure out how to dynamically find the arrays’ lengths at setup time, I ended up hardcoding these values in the first index of each array. It works but - even to a C novice like me - feels deeply inelegant and smacks of very poor programming practise.

I further put everything in Progmem (which does seem to save some memory on my Uno) but, again, not quite certain I’m going about it the right way as it’s my first real stab at it.

The approach I followed is derived from Macetech’s RGBShades code (particularly, the bits which involve storing and accessing his messages strings).

Hints, comments, suggestions, mild tut-tutting, rolling of eyes in despair, or any combination thereof are welcome.

Thanks

@Stuart_Taylor - I am looking forward to see how you implement sizeof() in this code. I tried to write some functions to do that without success.

On your snowflake drawing, you have the first pixel assigned the number 1. Don’t you want this to be zero and the other numbers lowered by one?

Here is a wild idea for you. If you consider all of your snowflakes as separate layers as if they were stacked one on top of another, couldn’t you use some of the awesome tree mapping method that @Jason_Coon used in his great Tree-V2 project? The code is here on GitHub:

FYI, I recently started writing sketches that use different mapping approaches in the same sketch for different animations. Such as using XY Matrix code along with my arrays of arrays code approach. I wrap it all together with @Mark_Kriegsman 's Time Performance Code. You might consider doing that too with your arrays of arrays approach along with Jason’s tree mapping approach. He has some amazing animations in these videos that you could use on your snowflakes:

and

@Ken_White ​ that my friend, is a plan so cunning, that you could stick a tail on it and call it a weasel!

A most excellent idea indeed. @Jason_Coon ​’s tree is spectacular. Thank you for the idea.

My sizeof() implementation feels very heavy handed. However i’m also more familiar with more modern languages that can handle this problem. Rummaging around in other peoples repo i can see the same sizeof() stanza used elsewhere, but it still feels like soemthing the compiler should be able to manage.

The snowflake drawing was produced to give to our friends in Shenzen for pricing, so its numbered for humans :wink:

Many thanks again!