Counting i think

So im only new to this and was hoping for some help!!

Im looking at what i think is a basic setup of triggering relays, Ive got the basic worked out but need some advise on the following:

what i want to do is split the program and run follow light flash for 6 rounds and then run the fast array for 6 but i also want to be able to add more functions in.

I was trying it with IF COUNT but i found that if i did that i could only do greater than or less than, but i think i need between 0-6 run loop 1 and between 7-12 run loop 2 then adding to this between 13-18 run loop 3 and so on.

I hope this makes sense. any help would be great!

//name the output pins int led1 = 6; int led2 = 7; int led3 = 8; int led4 = 9; int led5 = 10; int led6 = 11; int led7 = 12; int led8 = 13;

int timer1 = 300; int timer2 = 500; int timer3 = 50; int timer4 = 600;

// the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode( led1, OUTPUT); pinMode( led2, OUTPUT); pinMode( led3, OUTPUT); pinMode( led4, OUTPUT); pinMode( led5, OUTPUT); pinMode( led6, OUTPUT); pinMode( led7, OUTPUT); pinMode( led8, OUTPUT); }

// the loop routine runs over and over again forever: void loop() {

//follow light flash

digitalWrite(led1, HIGH); delay(timer1); digitalWrite(led1, LOW); digitalWrite(led2, HIGH); delay(timer1); digitalWrite(led2, LOW); digitalWrite(led3, HIGH); delay(timer2); digitalWrite(led3, LOW); digitalWrite(led4, HIGH); delay(timer1); digitalWrite(led4, LOW); digitalWrite(led5, HIGH); delay(timer1); digitalWrite(led5, LOW); digitalWrite(led6, HIGH); delay(timer2); digitalWrite(led6, LOW); digitalWrite(led7, HIGH); delay(timer2); digitalWrite(led7, LOW); digitalWrite(led8, HIGH); delay(timer1); digitalWrite(led8, LOW); delay(400);

// fast array digitalWrite(led1, HIGH); delay(timer3); digitalWrite(led2, HIGH); delay(timer3); digitalWrite(led1, LOW); delay(timer3); digitalWrite(led3, HIGH); delay(timer3); digitalWrite(led2, LOW); delay(timer3); digitalWrite(led4, HIGH); delay(timer3); digitalWrite(led3, LOW); delay(timer3); digitalWrite(led5, HIGH); delay(timer3);


Moderator edit: Please just cut and paste code between code tags

You'll find things go much easier if you learn to use arrays.

This would run your LED flash cycle 6 times

for (int count = 0; count < 6; count++)
   //code here to flash the LEDs 

but as AWOL has hinted you could considerably reduce your code by using arrays.

I would suggest that you try the for loop above with your existing LED code first to get used to how they work then consider using arrays to hold the pin numbers of the LEDs so that you can run through the array using another for loop.

Come back for more advice if you get stuck but please post the code you are stuck with and describe what is wrong as this makes it much easier to help.