4x4x4 RGB Cube rainbowduino. Everything works need help with the code

So I have a rainbowduino 4x4x4 RGB Cube from seedstudio. I've got this cube doing some stuff but I'm already at 32% on the chip is there a way to make my code more efficient and take up less space? I will attach the code on another post as I am not near my computer right now

// rainbowduino v3.0 library

#include <Rainbowduino.h>

void setup()
{
Rb.init(); //initialize Rainbowduino driver

}
unsigned int z,x,y;

void loop()
{
for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,3,0,0x00FF00);
}
}
delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,2,0,0xFF0000);
}
}
delay(100);
for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,1,0,0x00FF00);
}
}
delay(100);
for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,0,0,0xFF0000);
}
}
delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,0,1,0x00FF00);
}
}
delay(100);
for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,1,1,0xFF0000);
}
}
delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,2,1,0x00FF00);
}
}
delay(100);
for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,3,1,0xFF0000);
}
}
delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,3,2,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,2,2,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,2,2,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,1,2,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,0,2,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,0,3,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,1,3,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,2,3,0x09099C);
}
}

delay(100);

for(x=0;x<4;x++)
{
for(y=0;y<4;y++)
{
Rb.setPixelZXY(0,3,3,0x09099C);
}
}

delay(100);

// this now starts the second layer.

What's the deal with the for loops and not using x nor y in the commands?
Why unsigned int z,x,y; to count only up to 4? (A byte would do) and z is not used...

Try an empty sketch with just a call to Rb.setPixelZXY(0,2,3,0x09099C); in the loop to see what size you get from the library. Your code is probably tiny.

I just left my house but when I get back i will try that out and get back with you do I still need that for statement?

I don't know... your code is calling 16 times Rb.setPixelZXY(0,3,0,0x00FF00); pause for 0,1 sec, then 16 times Rb.setPixelZXY(0,2,0,0xFF0000); etc...

Do you need to call that 16 times? If not then get rid of the for loops and variables...

Yes I'm calling 16 different leds on the layer

Rb.setPixelZXY(0,3,0,0x00FF00); is an individual led call 0, is the led level. 3, is the x cord. And 0, is the you cord.

Here are some photos from there website. Which is:

http://wiki.seeedstudio.com/wiki/Rainbow_Cube
http://wiki.seeedstudio.com/wiki/File:Rainbow_Cube_kit_Block_Diagram.png

http://wiki.seeedstudio.com/wiki/File:Rainbow_Cube_LED_3D_Coordinates.png

Most of that 32% is probably the rainbowduino library code - it's an overhead that won't increase as you make your code more complex.

If you are looking for fun optimization hacks, consider this to loop through x,y, and z:

for(i=0;i<64;i++)
{
  x = (i >> 4) & 3;
  y = (i >> 2) & 3; 
  z = (i) & 3;

}

Yes I'm calling 16 different leds on the layer

Rb.setPixelZXY(0,3,0,0x00FF00); is an individual led call 0, is the led level. 3, is the x coord. And 0, is the y coord

So you call 16 time the same level, the same x and the same y? I would understand if your for loop variables x and y where in the function call....

PaulMurrayCbr:
Most of that 32% is probably the rainbowduino library code - it's an overhead that won't increase as you make your code more complex.

If you are looking for fun optimization hacks, consider this to loop through x,y, and z:

for(i=0;i<64;i++)

{
  x = (i >> 4) & 3;
  y = (i >> 2) & 3;
  z = (i) & 3;

}

I will have to try that out and I'm sitting at 32% with all four layers worth of code

J-M-L:
So you call 16 time the same level, the same x and the same y? I would understand if your for loop variables x and y where in the function call....

Sorry if I confused you my bad the first number represents the level. 0 is level one. 1 is level two. and 2 is level 3. and 3 is level four that's the first number. The second number goes from 0 to 3 as well. It's the x coordinate then the third number from 0 to 3 is your y coordinate the above post with the second link has a picture of the leds z x and y coordinates the third link shows the physical location of said leds location btw thank you guys for the help so far it's really appreciated! And apologies for my horrible grammar/punctuation.

Let me ask more directly:

What does Rb.setPixelZXY([color=red]0,3,0[/color],0x00FF00); do in the real world, in plain English?

(and if the answer is what I guess, What do you gain calling this 16 times in a row if it addresses always the same LED?)

J-M-L:
Let me ask more directly:

What does Rb.setPixelZXY([color=red]0,3,0[/color],0x00FF00); do in the real world, in plain English?

(and if the answer is what I guess, What do you gain calling this 16 times in a row if it addresses always the same pixel?)

It lights a led up with a color code. and I'm not calling the same pixel 16 times I'm calling 16 different pixels one after another.

Here is a link to the YouTube of my cube doing just that.

It lights a led up with a color code. and I'm not calling the same pixel 16 times I'm calling 16 different pixels one after another.

Explain to me how it addresses different pixlels given that the first 3 parameters of the call are numbers, not variables... I don't get it...

I can see you call it multiple times in other for loops with different parameters, so I agree you will light up different LEDs but I'm puzzled about why you need the 2 nested for loops ...

Okay the above image shows what the numbers stand for besides the numbers inside each box are ignored that's for an 8x8 display beings that the rainbowduino can drive both besides that I'm lost I was hoping you guys could explain. And I meant literally break it down to like the basics. I wanna learn this language but it's beating my brain up lol

PaulMurrayCbr:
Most of that 32% is probably the rainbowduino library code - it's an overhead that won't increase as you make your code more complex.

If you are looking for fun optimization hacks, consider this to loop through x,y, and z:

for(i=0;i<64;i++)

{
  x = (i >> 4) & 3;
  y = (i >> 2) & 3;
  z = (i) & 3;

}

so i copied your code in as you can see below

// rainbowduino v3.0 library 

#include <Rainbowduino.h>

void setup()
{
  Rb.init(); //initialize Rainbowduino driver
}
unsigned int z,x,y;

void loop()
{
 for(i=0;i<64;i++)
{
  x = (i >> 4) & 3;
  y = (i >> 2) & 3; 
  z = (i) & 3;
}
 }

but it throws an error the error is as follows:

"exit status 1 'i' was not declared in this scope"

Use for([color=red]int [/color]i=0;i<64;i++)... but not sure what you expect from this

One last go and then I give up on the explanation above - I think you (or me) don't understand.

I am saying that the 2 for loops in your code (same for all the others)

  for(x=0;x<4;x++)
  {
     for(y=0;y<4;x++)
     {
      Rb.setPixelZXY(0,3,0,0x00FF00);
      }
   }
   delay(100);

are totally useless because the setPixelZXY function you call has only numbers as parameters. You turn on with a given color 4 x 4 = 16 times the very same LED. you don't use x nor y.

So you are as good as doing

Rb.setPixelZXY(0,3,0,0x00FF00):
delay(100);

The for loops have no use. Get rid of all of them, only keep your Rb.setPixelZXY() calls and the delays and your lights will behave the very same way....

Having the for loops would make sense if you were calling Rb.setPixelZXY(3,[color=red]x,y[/color],0x0000FF);

Is that clear? Makes sense? (If not I give up)

thanks J-M-L it took the code with that correction. but doesn't do anything.

Exactly it does not do anything because you don't do anything with x,y and z any way - see my answer 14....

you answered my question lol. i see what was happening now because i ripped this code from a paint layer example so you have saved me space and you also explained that the for statement is for an entire layer thank you! this just made things a lot easier

Good, I was loosing hope :slight_smile:

Have fun!

Now to really rattle your brain.. lol the "for" statement what does it mean? like why does x =0 what does x <4 do? And what does x++ mean by the way thank you again. For the help above. As well