Simple Repeats

Hey all! Very new to programming and/or "tinkering" with the Arduino.

Last night, however, I took a shot a writing a VERY simple chaser program for the Arduino. I modified an existing design.. well, actually, I looked at it, tried to see if I could remember how to do it from memory, and switched the pins around, than decided to add one.

Well.. naturally I got hooked.. or a little TOO into it.. at which point several hours and a simple loop of 6 lights that went front to back and back again turned into.. well.. turned into this:

http://s284.photobucket.com/albums/ll23/dwb_43302/?action=view¤t=arduinodemo.mp4

And I haven't even uploaded the video of what THAT turned into.. I was having too much fun..

BUT ANYWAY!

Now I know that isn't particularly impressive to see the least, but I'm sure you can tell (if you watched it), many of the commands repeat (around four times) before going to another stage, repeat, another stage, and now I've repeated like 8 stages before it goes back to the beginning and loops.

My question is, I'm sure you've been waiting, is there any possible way to illicit the program to repeat the desired portion a specified number of times before it cycles to the next, to the next, etc. If you hadn't guessed, my code sheet is quite large (I'll post it if you'd like), and I'm thinking there has to be a way I'm completely oblivious to that would consolidate those portions.

Thanks guys! This thing is really neat! I should be reading a Sociology book but.. I just can't drag myself away from this..

post it, between code tags (# button above) and no doubt someone can help

Alright:

(also, thank you for telling me the code tag.. I didn't know how to do it and didn't want a 400 line reply)

void setup() //setup the pins
{
  pinMode(12, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(1, OUTPUT);
}

void loop() //begin programming behavior
{
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(12, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(1, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH); //quick flash back to 12
  delay(50);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(12, LOW);
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(12, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(1, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH); //quick flash back to 12
  delay(50);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(12, LOW);
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(12, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(1, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH); //quick flash back to 12
  delay(50);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(12, LOW);
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(12, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(2, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(1, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH); //quick flash back to 12
  delay(50);
  digitalWrite(4, HIGH);
  delay(50);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  delay(50);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  delay(50);
  digitalWrite(7, LOW);
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(8, LOW);
  digitalWrite(12, LOW);
  digitalWrite(12, HIGH); //begin dual flash sequence
  digitalWrite(4, HIGH);
  delay(500);
  digitalWrite(12, LOW);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(500);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(1, HIGH);
  delay(500);
  digitalWrite(7, LOW);
  digitalWrite(1, LOW); //end dual flash sequence
  digitalWrite(12, HIGH); //begin dual flash sequence
  digitalWrite(4, HIGH);
  delay(400);
  digitalWrite(12, LOW);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(400);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(1, HIGH);
  delay(400);
  digitalWrite(7, LOW);
  digitalWrite(1, LOW); //end dual flash sequence
  digitalWrite(12, HIGH); //begin dual flash sequence
  digitalWrite(4, HIGH);
  delay(300);
  digitalWrite(12, LOW);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(300);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(1, HIGH);
  delay(300);
  digitalWrite(7, LOW);
  digitalWrite(1, LOW); //end dual flash sequence
  digitalWrite(12, HIGH); //begin dual flash sequence
  digitalWrite(4, HIGH);
  delay(200);
  digitalWrite(12, LOW);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(200);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(1, HIGH);
  delay(200);
  digitalWrite(7, LOW);
  digitalWrite(1, LOW); //end dual flash sequence
  digitalWrite(12, HIGH); //begin dual flash sequence
  digitalWrite(4, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(4, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(7, LOW);
  digitalWrite(1, LOW); //end dual flash sequence
  digitalWrite(12, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  delay(50);
  digitalWrite(12, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  delay(50);
  digitalWrite(12, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  delay(50);
  digitalWrite(12, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  delay(50);
  digitalWrite(12, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  delay(50);
  digitalWrite(12, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(2, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  digitalWrite(2, LOW);
  digitalWrite(1, LOW);
  delay(50);
  digitalWrite(7, HIGH); //inside-out sequence
  digitalWrite(4, HIGH);
  delay(100);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  delay(100);
  digitalWrite(12, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(1, LOW);
  delay(100);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  delay(100);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  delay(100);
  digitalWrite(12, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(1, LOW);
  delay(100);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  delay(100);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  delay(100);
  digitalWrite(12, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(1, LOW);
  delay(100);
  digitalWrite(7, HIGH);
  digitalWrite(4, HIGH);
  delay(100);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(7, LOW);
  digitalWrite(4, LOW);
  delay(100);
  digitalWrite(12, HIGH);
  digitalWrite(1, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  delay(100);
  digitalWrite(12, LOW);
  digitalWrite(1, LOW);
}

As you can no doubt see at least two things: the first being I have little clue what I'm doing, and the second, many things repeat multiple times, which is kind of why I asked haha!

Hell, you can probably see how I ended up resorting to copy/paste to cut down time.

So yeah, that's pretty much it. One very large program that mostly repeats itself. I figure it's not a sweet LED cube or anything, so it should probably repeat a few times to get the point across.. haha, that sounds bad..

is there any possible way to illicit the program

What do you want to make illegal?

Haha, no sir, I guess poor word choice. I simply meant a workaround, by any means through the program, to get it to perform said task.

That actually makes me wonder: would it even be possible to get anything illegal out of the Arduino? The makers seem not just accepting of the fact that you can do as you please with it, but quite enthusiastic that you do exactly as such.

Sorry for the misunderstanding! That was my fault!

would it even be possible to get anything illegal out of the Arduino?

The dark side of the force will ...

I am guessing you would like to have LED pattern "sets". You could breakout the part of you code that just goes back and forth and call it "set 1" the next would be the "two led at a time set" etc.

You could do this using switch-case http://arduino.cc/en/Reference/SwitchCase . Then you could increment a Int# to switch the Led "set" you are running. You could even go a step farther and use Random to change the Int# running the "sets" http://arduino.cc/en/Reference/Random

I hope this is what you are talking about, there are other ways but, this is one, Mark