Loops within separate functions

Hi all,

I'm pretty new to this and undergoing what may be a little too ambitions a project! Hopefully there is a way of doing this that is less complicated than I'm making it.

I am making a time lapse camera trigger and pan motor set-up, where the delays for the trigger, pan and shot interval are all defined when the code begins using the button interface, and then the lapse begins once all variables meet conditions. I have all elements running ok in separate sketches, but bringing them together is proving tricky.

What I am aiming for, shown a rudimentary way:

int a; int b; etc

setup(){ startup msgs }

loop1(){ detect analog button presses etc (switch case based on analog values from LCD) set vars display lcd info etc quit loop when vars meet conditions }

loop2(){ use vars set in loop1 control stepper motor camera trigger }

The dilemma is that the analog buttons require a loop as they only use one pin and require repeated checking of the value to differentiate between the different buttons. The LCD is http://www.droboticsonline.com/index.php/arduino/arduino-shields/arduino-lcd-keypad-shield.html .

Any hints on how I could sort it out a bit, I have the camera trigger and stepper motor code running, and the initial variable setup code using the buttons, but how to merge the two? I'll post the code if needed. :astonished:

There are probably several methods to structure your application, but staying with what you have so far, does this make sense for a flow? :

int a;
int b;
etc

setup()
     {
       startup msgs
     }

void loop()
     {
       while (conditions not met)
         { 
           loop1()
         }
       loop2;
      }

loop1()
    {
      detect analog button presses etc (switch case based on analog values from LCD)
      set vars
      display lcd info etc
      quit loop when vars meet conditions
    }

loop2()
    {
      use vars set in loop1
      control stepper motor 
      camera trigger
    }

does this make sense for a flow?

Yes this is what I'm after, thanks for the quick reply. How do I go about declaring 'loop1' or 'loop2'. I'm not great with the syntax for functions...

Hampie42:

does this make sense for a flow?

Yes this is what I'm after, thanks for the quick reply. How do I go about declaring 'loop1' or 'loop2'. I'm not great with the syntax for functions...

That would be called function prototype definition and is required in normal C/C++ programs. However that's another thing the arduino IDE does for you automatically in it's preprocessing step(s) before handing your sketch off to the compiler, so you don't have to do anything, just write your functions, they can be written as you have outlined them at the end of the loop() function, even though you call them inside the loop() function.

Lefty

So I it will see it as a loop even if I call it 'loop1' ?

Hampie42:
So I it will see it as a loop even if I call it ‘loop1’ ?

?

When a function repeats or ends has nothing to do with what you name it, but rather the program structure and statements used inside the function.

Huh, well there you go. I did say I was a noob. Thanks for your help!