Super beginner needs help

Hello, Im modifying my kid's Proton pack for Halloween and decided use the Arduino that I got inside a box for ages, Im not a programmer or programmed anything in my life. Using examples I came up with a code, I just want to 7 leds to blink in sequence and 4 leds to blink randomly. I have to separated codes that work by itself, but I realized that if I put then together they will fail. Probably is very simple, but I tried a few things and I get errors compiling. Thank you.

Sequence of blinking lights

int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;




void setup() {
   pinMode(LED1, OUTPUT);
   pinMode(LED2, OUTPUT);
   pinMode(LED3, OUTPUT);
   pinMode(LED4, OUTPUT);
   pinMode(LED5, OUTPUT);
   pinMode(LED6, OUTPUT);
   pinMode(LED7, OUTPUT);
 
   
}


void loop() {
  digitalWrite(LED1, HIGH);    // turn on LED1 
  delay(100);                  // wait for 200ms
  digitalWrite(LED2, HIGH);    // turn on LED2
  delay(100);                  // wait for 200ms       
  digitalWrite(LED3, HIGH);    // turn on LED3 
  delay(100);                  // wait for 200ms
  digitalWrite(LED4, HIGH);    // turn on LED1 
  delay(100);                  // wait for 200ms
  digitalWrite(LED5, HIGH);    // turn on LED2
  delay(100);                  // wait for 200ms       
  digitalWrite(LED6, HIGH);    // turn on LED3 
  delay(100);                  // wait for 200ms
  digitalWrite(LED7, HIGH);    // turn on LED1 
  delay(100);                  // wait for 200ms



  
  digitalWrite(LED1, LOW);     // turn off LED1
  delay(100);                  // wait for 300ms
  digitalWrite(LED2, LOW);     // turn off LED2
  delay(100);                  // wait for 300ms
  digitalWrite(LED3, LOW);     // turn off LED3
  delay(100);                  // wait for 300ms before running program all over again
  digitalWrite(LED4, LOW);     // turn off LED1
  delay(100);                  // wait for 300ms
  digitalWrite(LED5, LOW);     // turn off LED2
  delay(100);                  // wait for 300ms
  digitalWrite(LED6, LOW);     // turn off LED3
  delay(100);                  // wait for 300ms before running program all over again
  digitalWrite(LED7, LOW);     // turn off LED1
  delay(100);                  // wait for 300ms

}

Random 4 leds blinking

#define numberOfLEDs 4
long nextFlash[4];
int ledPin[] = { 9, 10, 11, 12}; // LED pins to use.
int ledState[4];

void setup(){
for(int i = 0; i<numberOfLEDs; i++){
  pinMode(ledPin[i],OUTPUT);
  ledState[i] = LOW;
  digitalWrite(ledPin[i], LOW); // all LEDs off
    nextFlash[i] = millis() +random(100, 1000);
} 
}

void loop(){
for(int i = 0; i<numberOfLEDs; i++){
if(millis() > nextFlash[i]){
 if(ledState[i] == LOW) ledState[i] = HIGH; else ledState[i] = LOW;
 digitalWrite(ledPin[i],ledState[i]);
 nextFlash[i] = millis()+random(100, 1000) ; // next toggle random time
} }
}

Do you have 11 LED's? First, an Arduino can only "do" one thing at a time, so it can either flash the sequence, or randomly light some LED's. It can't do both at the same time. Given that limitation, how do you want the sketch to work?

Also, before you post your cope (BTW, thanks for using code tags!), place the cursor in the Source Code window and press Ctrl-T. That will reformat your code into a common C style. It makes it easier to read.

Are you sure you tried combing them? I just did and it compiles fine.

econjack:
Do you have 11 LED's? First, an Arduino can only "do" one thing at a time, so it can either flash the sequence, or randomly light some LED's. It can't do both at the same time. Given that limitation, how do you want the sketch to work?

Also, before you post your cope (BTW, thanks for using code tags!), place the cursor in the Source Code window and press Ctrl-T. That will reformat your code into a common C style. It makes it easier to read.

Yes, I have 11 leds, my plan was to make 7 leds in sequence and 4 blink randomly. I based my idea on this video, looks like she make 2 different pasterns.

DKWatson:
Are you sure you tried combing them? I just did and it compiles fine.

It gives the error:

exit status 1
redefinition of 'void setup()'

You can't have two setup() or two loop(). You have to take the code within each of those and combine.

DKWatson:
You can't have two setup() or two loop(). You have to take the code within each of those and combine.

I tried, but like I said, I kinda have no idea what Im doing. :frowning:

#define numberOfLEDs 4
unsigned long nextFlash[4];
int ledPin[] = { 9, 10, 11, 12}; // LED pins to use.
int ledState[4];
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;

void setup()
{
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);
    pinMode(LED5, OUTPUT);
    pinMode(LED6, OUTPUT);
    pinMode(LED7, OUTPUT);
    for (int i = 0; i < numberOfLEDs; i++)
    {
        pinMode(ledPin[i], OUTPUT);
        ledState[i] = LOW;
        digitalWrite(ledPin[i], LOW); // all LEDs off
        nextFlash[i] = millis() + random(100, 1000);
    }
}

void loop()
{
    digitalWrite(LED1, HIGH);    // turn on LED1
    delay(100);                  // wait for 200ms
    digitalWrite(LED2, HIGH);    // turn on LED2
    delay(100);                  // wait for 200ms
    digitalWrite(LED3, HIGH);    // turn on LED3
    delay(100);                  // wait for 200ms
    digitalWrite(LED4, HIGH);    // turn on LED1
    delay(100);                  // wait for 200ms
    digitalWrite(LED5, HIGH);    // turn on LED2
    delay(100);                  // wait for 200ms
    digitalWrite(LED6, HIGH);    // turn on LED3
    delay(100);                  // wait for 200ms
    digitalWrite(LED7, HIGH);    // turn on LED1
    delay(100);                  // wait for 200ms

    digitalWrite(LED1, LOW);     // turn off LED1
    delay(100);                  // wait for 300ms
    digitalWrite(LED2, LOW);     // turn off LED2
    delay(100);                  // wait for 300ms
    digitalWrite(LED3, LOW);     // turn off LED3
    delay(100);                  // wait for 300ms before running program all over again
    digitalWrite(LED4, LOW);     // turn off LED1
    delay(100);                  // wait for 300ms
    digitalWrite(LED5, LOW);     // turn off LED2
    delay(100);                  // wait for 300ms
    digitalWrite(LED6, LOW);     // turn off LED3
    delay(100);                  // wait for 300ms before running program all over again
    digitalWrite(LED7, LOW);     // turn off LED1
    delay(100);                  // wait for 300ms
    for (int i = 0; i < numberOfLEDs; i++)
    {
        if (millis() > nextFlash[i])
        {
            if (ledState[i] == LOW) ledState[i] = HIGH; else ledState[i] = LOW;
            digitalWrite(ledPin[i], ledState[i]);
            nextFlash[i] = millis() + random(100, 1000) ; // next toggle random time
        }
    }
}

Delta_G:
You can either sit there and lament that you don't know, and this costume will never be finished, or you can start studying how the Arduino works. Start with the basics. To get to where you want to be you don't need to get into anything too advanced. Just learning the basics will get you to completing this. Little kids learn that much and make projects way more complicated than this all the time. So there's really no reason to think you can't. You just need to take some time to do some reading. This site is a great resource, but there's a lot more to it than just the forum. There is a reference area and lots and lots of tutorials and getting started guides. Now is the time to start reading. It is not going to come to you overnight. It's going to take some time.

The other option, if you don't want to learn, would be to post in "Gigs and Collaborations" and offer to pay someone to write it for you.

I would gladly pay someone to make the code work properly. I would really like to learn because I think is fascinating, but I work a lot and would prefer spend time with my kid than learning just for this occasion. Perhaps when he is a little older we can learn together. :slight_smile:

Sorry for my English

If you want to pay someone to write a program for you please ask in the Gigs and Collaborations section of the Forum.

If you want to develop the program yourself then the demo Several Things at a Time may help. It uses millis() for non-blocking timing.

...R

This is now being handled in G&C. Perhaps a moderator could remove this thread.

Delta_G:
This is ridiculous. While it is true that the Arduino can only execute one command at a time and so technically can't do "two things at once", it can certainly do those things fast enough to handle both of these led patterns at once. It only requires that the two codes be written in a non-blocking fashion.

I don't get it. All I said was an Arduino cannot do two things at once. You then say that my statement is ridiculous, and then in the next sentence youo agree my statement is true...and it is. The OP, an admitted newbie, said he wanted to pulse two sets of LED's "at the same time". There's a difference between "at the same time" and "do those things fast enough to handle both of these led patterns at once". Sorry Delta-G, an Arduino cannot do that "at once".