led cube programming

Hi all, I am a beginner and I recently started writing some code and found it would be very useful to do some things which I am sure someone has already done. I need someone to point me to the right keywords here.

Essentially I have been addressing the individual LEDs by their two pins that turn one on and then putting a delay (of 1) and a for loop and addressing others when I want them to appear on at the same time. For this one program I wanted a wave to go from the bottom front right corner to the top left back corner and theres a stupid long code I wrote that does exactly that.

Someone must have figured out a way to address the LEDs in another way that allows them to be variable, and also making sections of the code change algorithmically to make this wave pattern (and any other variation of patterns). They must be some kind of objects they address them as in a spatial way, and I was wondering what kind of functions and tricks I might use to set up a way to begin programming this thing spatially rather than manually addressing each LED to form patterns.

Where do I start?

like is there some kind of way to do this with integers in matrices?

So, if you want a wave to go from the bottom left corner to the top back corner, than this means that at any moment, all leds where X+Y+Z = some value will be lit. To make the wave move, you bounce that value around.

I got it to move, but I want a more efficient way to code in general. Instead of writing

void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}

void loop()
{
digitalWrite (2,HIGH);
digitalWrite (11,HIGH);
delay (100);
digitalWrite (2,LOW);
digitalWrite (11,LOW);

for(int i=1; i<100;i++)

{
digitalWrite (3,HIGH);
digitalWrite (5,HIGH);
digitalWrite (11,HIGH);
delay (1);
digitalWrite (3,LOW);
digitalWrite (5,LOW);
digitalWrite (11,LOW);
digitalWrite (2,HIGH);
digitalWrite (12,HIGH);
delay (1);
digitalWrite (2,LOW);
digitalWrite (12,LOW);
i++;
}

for(int l=1; l<100;l++)

{
digitalWrite (11, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (8,HIGH);
delay (1);
digitalWrite (11, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (8,LOW);

digitalWrite (12, HIGH);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);

delay (1);
digitalWrite (12, LOW);
digitalWrite (3, LOW);
digitalWrite (5, LOW);
digitalWrite (13, HIGH);
digitalWrite (2, HIGH);
delay (1);
digitalWrite (13, LOW);
digitalWrite (2,LOW);
l++;
}
for(int k=1; k<100;k++)

{
digitalWrite (11, HIGH);
digitalWrite (7, HIGH);
digitalWrite (9, HIGH);

delay (1);
digitalWrite (11, LOW);
digitalWrite (7, LOW);
digitalWrite (9, LOW);

digitalWrite (12, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (8,HIGH);
delay (1);
digitalWrite (12, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (8, LOW);
digitalWrite (13, HIGH);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);
delay (1);
digitalWrite (13, LOW);
digitalWrite (3,LOW);
digitalWrite (5,LOW);
k++;
}
for(int m=1; m<100;m++)

{
digitalWrite (11, HIGH);
digitalWrite (10, HIGH);

delay (1);
digitalWrite (11, LOW);
digitalWrite (10, LOW);

digitalWrite (12, HIGH);
digitalWrite (9, HIGH);
digitalWrite (7, HIGH);
delay (1);
digitalWrite (12, LOW);
digitalWrite (7, LOW);
digitalWrite (9, LOW);
digitalWrite (13, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (8, HIGH);
delay (1);
digitalWrite (13, LOW);
digitalWrite (4,LOW);
digitalWrite (6,LOW);
digitalWrite (8,LOW);
m++;
}
for(int n=1; n<200;n++)

{
digitalWrite (7,HIGH);
digitalWrite (9,HIGH);
digitalWrite (13,HIGH);
delay (1);
digitalWrite (9,LOW);
digitalWrite (7,LOW);
digitalWrite (13,LOW);
digitalWrite (10,HIGH);
digitalWrite (12,HIGH);
delay (1);
digitalWrite (10,LOW);
digitalWrite (12,LOW);
n++;
}
digitalWrite (10,HIGH);
digitalWrite (13,HIGH);
delay (100);
digitalWrite (10,LOW);
digitalWrite (13,LOW);

digitalWrite (10,HIGH);
digitalWrite (13,HIGH);
delay (100);
digitalWrite (10,LOW);
digitalWrite (13,LOW);
for(int n=1; n<200;n++)

{
digitalWrite (7,HIGH);
digitalWrite (9,HIGH);
digitalWrite (13,HIGH);
delay (1);
digitalWrite (9,LOW);
digitalWrite (7,LOW);
digitalWrite (13,LOW);
digitalWrite (10,HIGH);
digitalWrite (12,HIGH);
delay (1);
digitalWrite (10,LOW);
digitalWrite (12,LOW);
n++;
}

for(int m=1; m<100;m++)

{
digitalWrite (11, HIGH);
digitalWrite (10, HIGH);

delay (1);
digitalWrite (11, LOW);
digitalWrite (10, LOW);

digitalWrite (12, HIGH);
digitalWrite (9, HIGH);
digitalWrite (7, HIGH);
delay (1);
digitalWrite (12, LOW);
digitalWrite (7, LOW);
digitalWrite (9, LOW);
digitalWrite (13, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (8, HIGH);
delay (1);
digitalWrite (13, LOW);
digitalWrite (4,LOW);
digitalWrite (6,LOW);
digitalWrite (8,LOW);
m++;
}

for(int k=1; k<100;k++)

{
digitalWrite (11, HIGH);
digitalWrite (7, HIGH);
digitalWrite (9, HIGH);

delay (1);
digitalWrite (11, LOW);
digitalWrite (7, LOW);
digitalWrite (9, LOW);

digitalWrite (12, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (8,HIGH);
delay (1);
digitalWrite (12, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (8, LOW);
digitalWrite (13, HIGH);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);
delay (1);
digitalWrite (13, LOW);
digitalWrite (3,LOW);
digitalWrite (5,LOW);
k++;
}

for(int l=1; l<100;l++)

{
digitalWrite (11, HIGH);
digitalWrite (4, HIGH);
digitalWrite (6, HIGH);
digitalWrite (8,HIGH);
delay (1);
digitalWrite (11, LOW);
digitalWrite (4, LOW);
digitalWrite (6, LOW);
digitalWrite (8,LOW);

digitalWrite (12, HIGH);
digitalWrite (3, HIGH);
digitalWrite (5, HIGH);

delay (1);
digitalWrite (12, LOW);
digitalWrite (3, LOW);
digitalWrite (5, LOW);
digitalWrite (13, HIGH);
digitalWrite (2, HIGH);
delay (1);
digitalWrite (13, LOW);
digitalWrite (2,LOW);
l++;
}
for(int i=1; i<100;i++)

{
digitalWrite (3,HIGH);
digitalWrite (5,HIGH);
digitalWrite (11,HIGH);
delay (1);
digitalWrite (3,LOW);
digitalWrite (5,LOW);
digitalWrite (11,LOW);
digitalWrite (2,HIGH);
digitalWrite (12,HIGH);
delay (1);
digitalWrite (2,LOW);
digitalWrite (12,LOW);
i++;
}
digitalWrite (2,HIGH);
digitalWrite (11,HIGH);
delay (100);
digitalWrite (2,LOW);
digitalWrite (11,LOW);
}

this, I would like to write something that will add another level or plane, and determine which leds should be lit for that level. I want to be able to make shapes algorithmically and translate it into which LEDs should be lit. Like another level I can input equations into and generate forms. How would I begin to code something like that?

Hi,
Please read this link ,then go back into your post and use code tags please.

They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

How many LEDs do you have and what arduino are you using? UNO?

Tom… :slight_smile:

TomGeorge:
Hi,
Please read this link ,then go back into your post and use code tags please.

They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

How many LEDs do you have and what arduino are you using? UNO?

Tom… :slight_smile:

@TomGeorge, perhaps you should make the link clickable? :wink:
http://forum.arduino.cc/index.php/topic,148850.0.html

Hi,

aarg, do you want me to do everything! ! !

Tom.... :slight_smile:

Ah, sorry about that!

Right now I am just using 27 LEDs, but the concepts I am looking to learn should be applicable to any size.

I posted my code as an example to show my long arduous way of creating this specific effect.

I guess my question is how can I write a function that will write code as it goes? For instance I want to start a wave across the cube as a plane going from bottom left back to top right front. I want to write something that will tell it that it needs to add digitalWrites for the next iteration of the propagation of the wave.

My other question (which could probably answer this question) is where can I go to find info on designing higher levels of programming for these things?

Are you thinking along these lines?

Code is in my library repository (link in the signature block below).