New to Arduino

int timer = 1000;           
int i = 1;

void setup() 
{  
  for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++)  
    for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)  
      for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
        for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
        {
          pinMode(thisPin1, OUTPUT);  
          pinMode(thisPin2, OUTPUT); 
          pinMode(thisPin3, OUTPUT); 
          pinMode(thisPin4, OUTPUT); 
          pinMode(51, OUTPUT);
          pinMode(52, OUTPUT);
          pinMode(53, OUTPUT);
        }
}


void loop()
{  
  while (i<2) {
    i++;
    {  
      for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++)  
        for (int thisPin2 = 13; thisPin2 < 25; thisPin2++) 
          for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
            for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
            { 
              digitalWrite(52, HIGH);
              delay(3000);
              digitalWrite(52, LOW);

              digitalWrite(thisPin1, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin1, LOW);

              digitalWrite(thisPin2, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin2, LOW);

              digitalWrite(thisPin3, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin3, LOW);

              digitalWrite(thisPin4, HIGH);
              digitalWrite(53, HIGH);
              delay(100);
              digitalWrite(53, LOW);
              delay(timer);
              digitalWrite(thisPin4, LOW);
            }
    }
  }
}

Oh, I see. Thank you very much. It was highlighted, but i did not see the error.

S

How many for loops are there in this code ?

    for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++)  
    for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)  
    for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
    for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
 {
    pinMode(thisPin1, OUTPUT);  
    pinMode(thisPin2, OUTPUT); 
    pinMode(thisPin3, OUTPUT); 
    pinMode(thisPin4, OUTPUT); 
    pinMode(51, OUTPUT);
    pinMode(52, OUTPUT);
    pinMode(53, OUTPUT);
}

Answers from the OP only, please.

I do have four rows of leds. And the shutter has to be controlled different at every row.
Is the code wrong? There is no more error code.

Thanks,

S

There is no more error code

That only means that the program is syntactically correct, and that the compiler has generated code for the code as written.
It does not necessarily mean that the code will do what you intended.

Does the code do what you intended?

The code is not exaclty wrong, more that it is unusual and unnecessary.
Try this, which as you will see is derived from your code.

void setup() 
{
  int counter =1;
  Serial.begin(9600);

  for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++)  
    for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)  
      for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
        for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
        {
          counter++;
        }
  Serial.println(counter);
}

void loop() {}

You may be surprised by the number of for loops that have been run. Explain in simple terms what you want those for loops to do.

I want to run 4 rows of leds and to every led i want to take a picture. And the shutter time should be different in every row.
Anyway. My code does not work properly.

My code does not work properly.

Because it is crap, as others have tried to point out.

If you were to use curly braces for every for loop, you'd see that. It is the nesting of the for loops that is wrong.

This is what you want:

  for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++) 
  {
     pinMode(thisPin1, OUTPUT);
  }
  for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)  
  {
     pinMode(thisPin2, OUTPUT);
  }
  for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
  {
     pinMode(thisPin3, OUTPUT);
  }
  for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
  {
     pinMode(thisPin4, OUTPUT);
  }

Now, what is the loop() function supposed to do? The nested loops there are probably wrong, too.

Thank you for your help! I really appreciate it.

I want to run 42 Leds in 4 different rows. 1 - 12, 13 -24, 25 - 36, 37 - 42 and as a Led lights up I want to take a picture.
The thing is, that I want to control the shutter time in every row. 1 second, 1/2 second, 1/4 second and 1/10 second for example.

And the loop should run only once!

Thank you.

S

And the loop should run only once!

Loop will run millions of times. If you want code executed only once, don't put it in loop(). Put it in setup().

I want to run 42 Leds in 4 different rows.

LEDs don't run. Try using some terms that make sense.

I have this code. This works fine.
But I am trying to control the camera shutter of the camera for every row with a different length.

While one led lights up, the shutter should open and than be closed.

_42fertig_rot.ino (536 Bytes)

PaulS:
This is what you want:

  for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++) 

{
     pinMode(thisPin1, OUTPUT);
  }
  for (int thisPin2 = 13; thisPin2 < 25; thisPin2++) 
  {
     pinMode(thisPin2, OUTPUT);
  }
  for (int thisPin3 = 24; thisPin3 < 38; thisPin3++) 
  {
     pinMode(thisPin3, OUTPUT);
  }
  for (int thisPin4 = 37; thisPin4 < 43; thisPin4++) 
  {
     pinMode(thisPin4, OUTPUT);
  }




Now, what is the loop() function supposed to do? The nested loops there are probably wrong, too.

or even

  for (int thisPin = 1;  thisPin < 43; thisPin++)
  {
     pinMode(thisPin, OUTPUT);
  }

which also avoids the overlaps in the limits of the for loops.
What's the point of setting the mode of a pin twice ? 8)

Perhaps when you put each { and each } on new lines, where they belong, I'll look at that code.

Perhaps when you put the code to be executed once in setup() where it belongs, I'll look at the code.

Perhaps when you stop saying "this code doesn't work" and explain what is actually does, what you want it to do, and how those two are different, I'll look at the code.

One code works fine.

With this the 42 leds light up one after the other and the camera takes a picture.

Now I am trying to control the shutter at each row (4).

But I do not get it, as you see.

Thanks,

S

sketch_feb12b.ino (1.44 KB)

But I do not get it, as you see.

Yes, I see.

Yes. Thats very obvious.

Now I got it. I guess.

The only problem I still could not solve is that the shutter of the camera does not close. Problaby something is wrong with the wires.

Anyway, thanks for your help.

S

sketch_feb12c.ino (1.19 KB)

The only problem I still could not solve is that the shutter of the camera does not close

The words "shutter" and "camera" appear nowhere in your code, so I'm afraid you'll have to sort that one yourself.

If I understand what the OP has said so far he wants the LEDs attached to pins 1 to 42 to turn on one after the other with a delay between them. There is some mechanism to cause a camera shutter to open and close each time every fourth LED turns on, but that mechanism does not form part of the sketch that has been posted. Each time the shutter opens it should remain open for an ever increasing length of time.

superschnitzel - have I described what you want to do correctly ? Is the Arduino controlling the opening and closing of the shutter and, if so, how ?

This is the latest version from above, formatted:

int timer = 2000;           
int i = 1;

void setup() 
{    
  pinMode(51, OUTPUT);
  pinMode(52, OUTPUT);
  pinMode(53, OUTPUT);
  {   
    digitalWrite(52, HIGH);
    delay(5000);
    digitalWrite(52, LOW);
  }
  {   
    for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++) 
    {   
      pinMode(thisPin1, OUTPUT);
      digitalWrite(thisPin1, HIGH);
      digitalWrite(51, HIGH);
      delay(1000);
      digitalWrite(51, LOW);
      delay(timer);
      digitalWrite(thisPin1, LOW);
    }
    for (int thisPin2 = 13; thisPin2 < 25; thisPin2++)  
    {   
      pinMode(thisPin2, OUTPUT);
      digitalWrite(thisPin2, HIGH);
      digitalWrite(51, HIGH);
      delay(500);
      digitalWrite(51, LOW);
      delay(timer);
      digitalWrite(thisPin2, LOW);
    }
    for (int thisPin3 = 24; thisPin3 < 38; thisPin3++)  
    {   
      pinMode(thisPin3, OUTPUT);
      digitalWrite(thisPin3, HIGH);
      digitalWrite(51, HIGH);
      delay(250);
      digitalWrite(51, LOW);
      delay(timer);
      digitalWrite(thisPin3, LOW);


    }
    for (int thisPin4 = 37; thisPin4 < 43; thisPin4++)  
    {   
      pinMode(thisPin4, OUTPUT);
      digitalWrite(thisPin4, HIGH);
      digitalWrite(51, HIGH);
      delay(100);
      digitalWrite(51, LOW);
      delay(timer);
      digitalWrite(thisPin4, LOW);
    }
  }
}



void loop(){
}

This is just a jumble of numbers. Is pin 51 the shutter? If so, how about saying so?

const byte shutterPin = 51;

...

   for (int thisPin1 = 1;  thisPin1 < 13; thisPin1++) 
    {   
      pinMode(thisPin1, OUTPUT);
      digitalWrite(thisPin1, HIGH);
      digitalWrite(shutterPin, HIGH);
      delay(1000);
      digitalWrite(shutterPin, LOW);
      delay(timer);
      digitalWrite(thisPin1, LOW);
    }

And what are 13, 25, 24, 38, 37, 43? Meaningful names will help you and help us.