adjust parameters before starting loop?

I am about to start writing a sketch and haven't done so in about 6 months so am a little rusty and could just do with a point in the right direction of were to start.

essentially what I am trying to do is create a time lapse intervalometer, in terms of triggering the camera im all fine, and I have looked at a few examples but most were either too simple, or had way more functions than I need.

How I envision this to work is that there are two sets of parameters, shutter time, and Interval time. due to not wanting to spend any money and use what I already have I am intending to have 3 buttons: shutter speed, interval time, and "start". with several LED's to indicate which preprogrammed time has been been selected.

this is how i see it working:

S is shutter speed, I is interval, both will have several selections, so for this i will number them ie S1, S2 etc.

push button S once - S1 is selected - LED1 is on briefly, push again - S2 is selected, LED2 is on briefly etc.

push button I once - I1 is selected - LED1 is on briefly, push again - I2 is selected, LED2 is on briefly etc. (same set of LED's)

push "Start" - loop will start tuning camera shutter on for S* and then off for I*

any help would be greatly appreciated even if it points to another thread that might help

Loading... this is what im basing the rest of the code on if this helps anybody help me :D.

you can set all of this up in the loop, just use a variable to define "states", ie in BSCODE (thats bulls... code)

vstate = 0

if vstate == 0 then
do setup stage one
end

though if you need little overhead in the loop, checking a handful of states could be a problem every single loop, so order appropriately, maybe make your main running state 0 and all your setup states after, so the program wont check 3-4 different conditions before getting to your main functionality

also look at switch/case, which is like a handful of "if" statements, but less wordy (and perhaps a bit more efficient in small numbers)

You want to keep running loop even when you haven't started capturing yet.
I'm assuming you want to keep capturing with the set values until the start button is pressed again.
The code in loop would look something like this (pseudo-code):

int S = 0;
int I = 0;
unsigned long shutterDelay;
unsigned long intervaDelay;
bool running = false;
unsigned long shutters[NUM_S_VALUES} = { 10, 20, 40, ... };
unsigned long intervals[NUM_I_VALUES] = { 100, 200, 400, ... };

void loop() {
  if (running) {
    if (start pressed) {
      running = false;
      turn off shutter if needed
    }
    else {
      handle shutter being on or off
      (see "blink without delay" sample)
    }
  }
  else {
    if (S pressed) {
      digitalWrite(FIRST_S_PIN + S, LOW);
      S += 1;
      if (S >= NUM_S_OPTIONS) {
        S = 0;
      }
      digitalWrite(FIRST_S_PIN + S, HIGH);
    }
    if (I pressed) {
      digitalWrite(FIRST_I_PIN + I, LOW);
      I += 1;
      if (I >= NUM_I_OPTIONS) {
        I = 0;
      }
      digitalWrite(FIRST_I_PIN + I, HIGH);
    }
    shutterDelay = shutters[S};
    intervalDelay = intervals[I};
    if (start pressed) {
      running = true;
      startTime = millis();
    }
  }
}

thanks heaps just what I needed, just needed someone to jog my memory :slight_smile: that'll give me something to play around with