Voiding a loop within the code

Hi guys, I'm new to Arduino and I'm having some issues with my code. As you can see, in my code in case 1 I have an LED that blinks. What I really want is for that part of the code to run only once when I run case 1 and then I can still use my If statement in a loop. So basically I want ledPinOne to blink once then stay on for the whole time im in case one. Thanks guys!!!

int counter = 0;
int modeSelect = 12;
const int ledPinOne = 11; 
const int ledPinTwo = 10; 
const int ledPinThree = 9;
const int pin = 4;
const int triggerI = 5;
const int triggerO = 3;
int a = 0;
int v = 0;

void setup() {
 pinMode(ledPinOne, OUTPUT);
 pinMode(ledPinTwo, OUTPUT);
 pinMode(ledPinThree, OUTPUT);
 pinMode(modeSelect, INPUT);
 pinMode(pin, INPUT);

void loop() {
  a = digitalRead(pin);
  v = analogRead(triggerI);

  int val = 0;
  int switchVal = digitalRead(modeSelect);
  if(switchVal == HIGH)
    counter ++;
        if(counter == 3) //Reset count if over max mode number
      counter = 0;

    switch (counter) {
    case 0:
      digitalWrite(ledPinOne, LOW);
      digitalWrite(ledPinTwo, LOW);
      digitalWrite(ledPinThree, LOW);
      analogWrite(triggerO , v );
    case 1: // RAPID FIRE  

      digitalWrite(ledPinOne, HIGH);
      digitalWrite(ledPinOne, LOW);

      if (a == HIGH){
        digitalWrite(ledPinThree, HIGH);
        digitalWrite(ledPinThree, LOW);
    case 2: // DROP SHOT
      digitalWrite(ledPinOne, LOW);
      digitalWrite(ledPinTwo, HIGH);


Had a same issue, the simplest way for me was to set a "fall thru" case which basically does nothing and keeps the loop running. It is a crude state machine and it can get difficult to keep track of things. IMHO the real issue is to get rid of the loop in case you do not need it. I'll eventually replace it with something else. Cheers Vaclav

I did something very similar to this for a prop gun I helped build for a friend.

Basically, I had to take all of the functions out of the loop and move them off to sub routines. The best thing you can do is learn to segment your code into functions and routines. Don't mind the code, this is for instructional purposes.

But you only want Actionable logic in the LOOP, and then all of the actions in functions, subroutines, etc...

So, on CASE 1: led1 == HIGH; delay(50); led1 == LOW; leaveLEDonUntilYouLetGoOfTrigger(); break;

void leaveLEDonUntilYouLetGoOfTrigger(){ while (vPin == HIGH) { // or however you say the trigger is held down LED1=HIGH; //keeps the led on because your trigger pin is pressed } LED1=LOW; //resets.. you could also do this with an IF.. if (vPIN == low){LED1=LOW} }

Good luck!