Need help with code, PLEASE

Hi everyone, I'm new to Arduino and C programming. I have built a 5x5x5 LED cube mono colour using 20 pins and learning some simple programming.

Is it possible to group a series of actions (rain effect, ie top LED on/off to the bottom). I'm writing the code and its quite large.

My question is, Instead of writing out the code in full can I call in a function, ie X=TOP LED, NEXT LED,....., BOTTOM LED.

And how can I group the delays instead of writing it out, over and over because if I want to change the speed I have to do it individually.

Below I have some of the code for one LED going from top to the bottom.

I would appreciate any help,

void setup()
{
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
pinMode(14, INPUT);
pinMode(15, INPUT);
pinMode(16, INPUT);
pinMode(17, INPUT);
pinMode(18, INPUT);
pinMode(19, INPUT);
pinMode(20, INPUT);
}

void loop()
{
pinMode(5, OUTPUT); //TOP LED//
pinMode(19, OUTPUT);
digitalWrite(5, HIGH);
digitalWrite(19, LOW);
delay(50);
pinMode(5, INPUT);
pinMode(19, INPUT);

pinMode(19, OUTPUT); //NEXT LED//
pinMode(5, OUTPUT);
digitalWrite(19, HIGH);
digitalWrite(5, LOW);
delay(50);
pinMode(19, INPUT);
pinMode(5, INPUT);

pinMode(5, OUTPUT); //NEXT LED//
pinMode(20, OUTPUT);
digitalWrite(5, HIGH);
digitalWrite(20, LOW);
delay(50);
pinMode(5, INPUT);
pinMode(20, INPUT);

pinMode(20, OUTPUT); //NEXT LED//
pinMode(5, OUTPUT);
digitalWrite(20, HIGH);
digitalWrite(5, LOW);
delay(50);
pinMode(20, INPUT);
pinMode(5, INPUT);

pinMode(6, OUTPUT); //BOTTOM LED//
pinMode(5, OUTPUT);
digitalWrite(6, HIGH);
digitalWrite(5, LOW);
delay(50);
pinMode(6, INPUT);
pinMode(5, INPUT);
}

You need to read about "for" loops and "arrays".

Thanks AWOL for your reply,

I'm a total newbie to the C programming. I have looked at the reference for "FOR" and "ARRAY" but I don't understand how I can apply/manipulate it to do what I want. Will need to keep trying...

Awesome job getting the 5x5x5 LED array hardware working! That's cool.

Using a function can also make your life easier.

/*
* Turn LED at row i, col j, and layer k either on or off depending on state
*/
void flashLED(int i, int j, int k, boolean state){
  int lo_pin = XXX // you need to figure this out
  int hi_pin = XXX // you need to figure this out

  pinMode(hi_pin, OUTPUT); //TOP LED//
  pinMode(lo_pin, OUTPUT);
  digitalWrite(hi_pin, HIGH);   
  digitalWrite(lo_pin, LOW);
  delay(50);
  pinMode(hi_pin, INPUT);
  pinMode(lo_pin, INPUT);

Then a single falling drop down the middle might look like this:

for(int k = 4; k >= 0; k--){
 flashLED(3, 3, k);
}

Please post pictures and videos!
Justin

Thanks a million for that Justin really appreciate it mate, I'll get some pics and a video up once I've got some good code together.

Pabs