Camera & turntable loop

Hello,

I'm trying to automate my camera and turntable (take a photo, rotate turntable, repeat 3 times & stop).

Code is working fine, but it just keeps going on forever.

How do I insert a set number of loops?

Thank you for any suggestions

int _ABVAR_1_;

void setup()
{
pinMode( 9 , OUTPUT);
pinMode( 8 , OUTPUT);
pinMode( 6 , OUTPUT);
}

void loop()
{
for (_ABVAR_1_=0; _ABVAR_1_< ( 3 ); ++_ABVAR_1_ )
{
digitalWrite( 6 , HIGH ); //relay on
delay( 2000 );
digitalWrite( 6 , LOW ); //relay off
delay( 2000 );
digitalWrite( 8 , HIGH ); //camera focus
delay( 1500 );
digitalWrite( 9 , HIGH );  //say cheese
delay( 1000 );
digitalWrite( 8 , LOW );
digitalWrite( 9 , LOW );
delay( 2000 );
}

}

Put it in setup(), not loop(). Leave loop() empty.

Thanks, I have re-arranged the code, but it will not verify.
Sorry, I am brand new to arduino

int _ABVAR_1_;

void setup()
{
pinMode( 9 , OUTPUT);
pinMode( 8 , OUTPUT);
pinMode( 6 , OUTPUT);

for (_ABVAR_1_=0; _ABVAR_1_< ( 3 ); ++_ABVAR_1_ )
{
digitalWrite( 6 , HIGH );
delay( 2000 );
digitalWrite( 6 , LOW );
delay( 2000 );
digitalWrite( 8 , HIGH );
delay( 1500 );
digitalWrite( 9 , HIGH );
delay( 1000 );
digitalWrite( 8 , LOW );
digitalWrite( 9 , LOW );
 
}
void loop(){


 
 
}

Use Ctrl-T in the IDE to reformat the code in a standard format. Your missing bracket will be obvious from the indentation. Use blank lines sparingly, no more than one at a time.

Use blank lines sparingly, no more than one at a time.

I'd say use blank lines and whitespace generously, keep layout clear and uncrowded for
maximum readability.

But yes, an empty function body doesn't need any extra blank-ness, its between the functions and sections
that blank lines are most appropriate. Just like any document, whitespace is excellent at conveying
structure to human readers, so use it.

MarkT:
I'd say use blank lines and whitespace generously, keep layout clear and uncrowded for
maximum readability.

But yes, an empty function body doesn't need any extra blank-ness, its between the functions and sections
that blank lines are most appropriate. Just like any document, whitespace is excellent at conveying
structure to human readers, so use it.

I would say, use it "groupingly". For example I might change

digitalWrite( 9 , HIGH );
delay( 1000 );
digitalWrite( 8 , LOW );
digitalWrite( 9 , LOW );
 
}
void loop(){

to

digitalWrite( 9 , HIGH );

delay( 1000 );

digitalWrite( 8 , LOW );
digitalWrite( 9 , LOW );
}

void loop(){

to show functionality... we do some digital writes, then we delay, then more writes, finished block, now start a new function... etc.

While we're on the subject...
There are many other things that programmers do to make their code understandable. Use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Give things descriptive names. Use descriptive variable names, for example "temperature" instead of "t". You can name numerical constants, pin numbers, variables and many other things in this way. For example, you can refer to a pin and an output level by number, like digitalWrite(3,0). But such a statement doesn't reveal anything about the purpose. digitalWrite(hornRelayPin, LOW) does. You can do that by declaring const byte hornRelayPin = 3; before setup() in your program. Many such names are already defined for you by the compiler and the Arduino IDE. Here are some:

#define HIGH 0x1
#define LOW  0x0
#define PI 3.1415926535897932384626433832795

Use them. There are many more. Use compiler math to compute values so you can see where they came from (or at least document them). For example, if you see the number 73, you would be hard put to explain the significance of it. But if you see "daysPerYear/5", it is obvious. One more thing. When you work on program continuously, you become familiar with it. So many things seem obvious even if they are not spelled out explicitly. But try looking at your own code six months later. It will be as if a stranger wrote it. So write for strangers, not yourself.

"ABVAR_1" doesn't tell you much, and the leading underscore makes it look like a system variable.

I have reformat the code and I'm close....just need help putting the brackets in the right place

Can someone help correct the brackets please. I've tried nearly every way without success :o

int _ABVAR_1_;

void setup()
{
  pinMode( 9 , OUTPUT);
  pinMode( 8 , OUTPUT);
  pinMode( 6 , OUTPUT);
}
for (_ABVAR_1_ = 0; _ABVAR_1_ < ( 2 ); ++_ABVAR_1_ )
{
  digitalWrite( 6 , HIGH );
  delay( 2000 );
  digitalWrite( 6 , LOW );
  delay( 2000 );
  digitalWrite( 8 , HIGH );
  delay( 1500 );
  digitalWrite( 9 , HIGH );
  delay( 1000 );
  digitalWrite( 8 , LOW );
  digitalWrite( 9 , LOW );
  delay( 2000 );
}
  void loop()
  {

  }

}

Oh, come on. Start comparing it with other simple sketches. You'll get it. You did put it in setup() as I described the first time. Then you went back and messed it up. Hint - all code goes inside some function. setup() and loop() are separate functions.

When I try inserting the brackets as below, the code uploads, but the relay does not switch off after 2 seconds.
So, I'm wondering if I should separate the repeat part of the code with another bracket somewhere?
(my explanation / excuse for throwing in too many brackets last time)

 int _ABVAR_1_;

void setup()
{
pinMode( 9 , OUTPUT);
pinMode( 8 , OUTPUT);
pinMode( 6 , OUTPUT);

for (_ABVAR_1_=0; _ABVAR_1_< ( 3 ); ++_ABVAR_1_ )

digitalWrite( 6 , HIGH );//relay on
delay( 2000 );
digitalWrite( 6 , LOW );//relay off
delay( 2000 );
digitalWrite( 8 , HIGH );//camera focus
delay( 1500 );
digitalWrite( 9 , HIGH );//say cheese
delay( 1000 );
digitalWrite( 8 , LOW );
digitalWrite( 9 , LOW );
 
}
void loop(){

}

You're missing the curly brackets around the for loop statements, only the first line in the for loop executes 3 times, the rest of the lines execute once.

I'm still confused....
Inserted brackets, but still not working

int _ABVAR_1_;

void setup()
{
  pinMode( 9 , OUTPUT);
  pinMode( 8 , OUTPUT);
  pinMode( 6 , OUTPUT);

  {
    for (_ABVAR_1_ = 0; _ABVAR_1_ < ( 3 ); ++_ABVAR_1_ )
    }

  digitalWrite( 6 , HIGH );//relay on
  delay( 2000 );
  digitalWrite( 6 , LOW );//relay off
  delay( 2000 );
  digitalWrite( 8 , HIGH );//camera focus
  delay( 1500 );
  digitalWrite( 9 , HIGH );//say cheese
  delay( 1000 );
  digitalWrite( 8 , LOW );
  digitalWrite( 9 , LOW );

}
void loop() {

}

Read this more closely.

edgemoron:
You're missing the curly brackets around the for loop statements,...

Then check out for loop