Go Down

Topic: 4x4x4 RGB Cube rainbowduino. Everything works need help with the code (Read 2318 times) previous topic - next topic

cyriss

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

cyriss

// 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.

J-M-L

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.
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

cyriss

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?

J-M-L

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...
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

cyriss

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

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:

Code: [Select]

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

}


http://paulmurraycbr.github.io/ArduinoTheOOWay.html

J-M-L

Quote
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....
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

cyriss

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:

Code: [Select]

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


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.

J-M-L

Let me ask more directly:

What does Rb.setPixelZXY(0,3,0,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?)
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

cyriss

Let me ask more directly:

What does Rb.setPixelZXY(0,3,0,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.

https://youtu.be/1Y9Z4h9xRhc

J-M-L

Quote
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 ...
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

cyriss



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

cyriss

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:

Code: [Select]

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


Code: [Select]

// 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"

J-M-L

Use for(int 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)
Code: [Select]

  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

Code: [Select]

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,x,y,0x0000FF);

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







Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

Go Up