For loop won't stop

Hello,

I'm working on a project that requires a camera to fire x number of times, but for some reason the loops continues even though the loop's conditions are no longer met. My set up is pretty simple - I'm using a 10k pullup resistor connected to a switch. When I upload the code and press the button the sequence kicks off as it should. I can see in the serial that the input pin changes to "0" when the button is pressed and goes back "1" when released. If the input reads "1" after the loop completes why would the loop continue since the specified value to start the loop is no longer met? Any help on this would be greatly appreciated.

const int trigger_lr = 8; // trigger button for standard strobe capture
const int trigger_uv = 9; // trigger button for UV capture
int trigger_read_lr;
int trigger_read_uv;
const int cam_fire = 10;

int ledPin = 7;
int enable = 1;
int inputA = 2;
int inputB = 3;
int strobe_fire = 12;
int UV_fire = 11;
int lr_loop = 5;
int UV_loop = 10;
int i;



void setup()
{ // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(trigger_lr, INPUT);
  pinMode(trigger_uv, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(cam_fire, OUTPUT);
  pinMode(enable, OUTPUT);
  pinMode(inputA, OUTPUT);
  pinMode(inputB, OUTPUT);
  pinMode(strobe_fire, OUTPUT);
  pinMode(UV_fire, OUTPUT);



  // clearpath motor inputs set to off
  digitalWrite(enable, LOW);
  delay(10);
  digitalWrite(inputA, LOW);
  digitalWrite(inputB, LOW);

while (digitalRead(trigger_lr) == HIGH);
    
}

// end of setup code
void loop() {
  // put your main code here, to loops indefinitely:
  Serial.println(trigger_read_lr);
  delay(250);
  trigger_read_lr = digitalRead(trigger_lr);
  delay(500);
  
  
  
  if (trigger_lr == LOW); {
      for (i = 1; i <= lr_loop ; i = i+1)
      digitalWrite(cam_fire, HIGH);
      delay(100);
      digitalWrite(cam_fire, LOW);
  }  
  if (digitalRead(trigger_lr) == HIGH); {
   digitalWrite(cam_fire, LOW);
  }
  }


// end of main code, will loop indefinitely

You for loop is missing {}...

Not only is the 'for' wrong, but also the 'if'.

You need to learn the basic syntax of the language.

Your conditions are useless because of superficial ';' after them:

Your for loop doesn't have a body except of the one line after it:

:+1:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.