Long Button Press LED & Buzzer

So i am working on a project for 4 LEDs and buzzer.
Holding down the button for 5 seconds turns on LED1, (continue) holding Turns on LED2), LED 3 and LED 4, Then and 31 seconds the buzzer just goes high.
BUT as soon as the button is releases it would abort and reset.

Trying to figure out my issue here…
-It WONT Reset When i release the button

Thanks in advance

//Prop  Simple, one mode

#define buttonPin 10 // analog input pin to use as a digital input
#define ledPin1 3 // digital output pin for LED 1 indicator
#define ledPin2 4 // digital output pin for LED 2 indicator
#define ledPin3 5
#define ledPin4 8
#define Buzzer 12 



byte
    currSwitch,
    lastSwitch;
unsigned long
    timeStart;
bool
    bCheckingSwitch;   
void setup()
{
    pinMode( ledPin1, OUTPUT );
    digitalWrite( ledPin1, LOW );
    pinMode( ledPin2, OUTPUT );
    digitalWrite( ledPin2, LOW );
    pinMode( ledPin3, OUTPUT );
    digitalWrite( ledPin3, LOW );
    pinMode( ledPin4, OUTPUT );
    digitalWrite( ledPin4, LOW );
    pinMode( Buzzer, OUTPUT );
    digitalWrite( Buzzer, LOW );
    pinMode( buttonPin, INPUT_PULLUP );
    lastSwitch = digitalRead( buttonPin );
    bCheckingSwitch = false;
   
}//setup

void loop()
{
    //read the switch (for simplicity, no debouncing done)
    currSwitch = digitalRead( buttonPin );
    //if the switch is low now and doesn't match its
    //previous reading, it means the switch has changed
    //either unpressed-to-pressed or pressed-to-unpressed
    if( currSwitch != lastSwitch )
    {
        //if low now, the change was unpressed to pressed
        if( currSwitch == LOW )
        {
            //in that case, get the time now to start the
            //5-sec delay...
            timeStart = millis();
            //...indicate we're now timing a press...
            bCheckingSwitch = true;
           
        }//if
        else
        {
            //was a rising edge (button being released)
            //cancel checking the switch timing now since
            //it's not being held hown
            bCheckingSwitch = false;
           
        }//else
       
        //and save the
        lastSwitch = currSwitch;
       
    }//if

    //if we haven't seen a rising edge, keep checking the
    //timing
    if( bCheckingSwitch )
    {
        //if the millis count now is 5000 or more higher
        //than it was when the press was detected (timeStart),
        //turn on the LED
        if( (millis() - timeStart ) >= 5000 )
            digitalWrite( ledPin1, HIGH );   
        if( (millis() - timeStart ) >= 15000 )
            digitalWrite( ledPin2, HIGH );
            if( (millis() - timeStart ) >= 25000 )
            digitalWrite( ledPin3, HIGH ); 
            if( (millis() - timeStart ) >= 28000 )
            digitalWrite( ledPin4, HIGH ); 
            if( (millis() - timeStart ) >= 31000 )
            digitalWrite( Buzzer, HIGH );  
    }//if
   
}//loop

That doesn't compile - your braces are out of place.

This compiles good now on my end.

Just cant get it to reset if at any time the button is released.

//Prop Bomb Simple, one mode

#define buttonPin 10 // analog input pin to use as a digital input
#define ledPin1 3 // digital output pin for LED 1 indicator
#define ledPin2 4 // digital output pin for LED 2 indicator
#define ledPin3 5
#define ledPin4 8
#define Buzzer 12 



byte
    currSwitch,
    lastSwitch;
unsigned long
    timeStart;
bool
    bCheckingSwitch;   
void setup()
{
    pinMode( ledPin1, OUTPUT );
    digitalWrite( ledPin1, LOW );
    pinMode( ledPin2, OUTPUT );
    digitalWrite( ledPin2, LOW );
    pinMode( ledPin3, OUTPUT );
    digitalWrite( ledPin3, LOW );
    pinMode( ledPin4, OUTPUT );
    digitalWrite( ledPin4, LOW );
    pinMode( Buzzer, OUTPUT );
    digitalWrite( Buzzer, LOW );
    pinMode( buttonPin, INPUT_PULLUP );
    lastSwitch = digitalRead( buttonPin );
    bCheckingSwitch = false;
   
}//setup

void loop()
{
    //read the switch (for simplicity, no debouncing done)
    currSwitch = digitalRead( buttonPin );
    //if the switch is low now and doesn't match its
    //previous reading, it means the switch has changed
    //either unpressed-to-pressed or pressed-to-unpressed
    if( currSwitch != lastSwitch )
    {
        //if low now, the change was unpressed to pressed
        if( currSwitch == LOW )
        {
            //in that case, get the time now to start the
            //5-sec delay...
            timeStart = millis();
            //...indicate we're now timing a press...
            bCheckingSwitch = true;
           
        }//if
        else
        {
            //was a rising edge (button being released)
            //cancel checking the switch timing now since
            //it's not being held hown
            bCheckingSwitch = false;
           
        }//else
       
        //and save the
        lastSwitch = currSwitch;
       
    }//if

    //if we haven't seen a rising edge, keep checking the
    //timing
    if( bCheckingSwitch )
    {
        //if the millis count now is 5000 or more higher
        //than it was when the press was detected (timeStart),
        //turn on the LED
        if( (millis() - timeStart ) >= 5000 )
            digitalWrite( ledPin1, HIGH );   
        if( (millis() - timeStart ) >= 15000 )
            digitalWrite( ledPin2, HIGH );
        if( (millis() - timeStart ) >= 25000 )
            digitalWrite( ledPin3, HIGH ); 
        if( (millis() - timeStart ) >= 28000 )
            digitalWrite( ledPin4, HIGH ); 
        if( (millis() - timeStart ) >= 31000 )
            digitalWrite( Buzzer, HIGH );  
    }//if
   
}//loop

What do you mean by reset? All LEDs and buzzer shut off? If that is the case, then you need to do exactly that when you detect the switch was released, i.e. digitalWrite(pin, LOW) for all connected outputs.

Right so if the button is released all LEDs and buzzer would shut off and the program would wait a the beginning for input again.

StrikeforcePC:
Right so if the button is released all LEDs and buzzer would shut off and the program would wait a the beginning for input again.

Correct.

I dont really understand.
Where do I put and how do I tell it to look for it to Check constantly for a release of the button.

Another “if” before the Timing section?
Or put it in the timing section?

You just need to add the LOW digitalWrites after your bCheckingSwitch = false; statement.

No, I think you misunderstand how it works. The controller doesn’t wait it just loops over and over in the loop. So just imagine you are reading your odd line by line and following the instructions. When you get to the end go back to the beginning and read through again. You are using if statements so it will check if the statement is true and then carry out the instructions in your braces. If it is false it just skips on.

Yes, the statements enclosed in loop() are supposed to be executed several thousand times a second.

That worked guys thanks!

One more thing.

I want to add a servo, when a switch/key is connected, it moves the servo.

How do i add that (its almost a separate little program)

I did this, but its not working :frowning:

 #include <Servo.h> 
int pos=0;
#define buttonPin 10 // analog input pin to use as a digital input
#define ledPin1 3 // digital output pin for LED 1 indicator
#define ledPin2 4 // digital output pin for LED 2 indicator
#define ledPin3 5
#define ledPin4 8
#define Buzzer 12 
#define LaunchKey 11
#define Smoke 2 //Smoke is a Relay to a rechargable 3Cell Lipo (which also can run the Chasing Lights). 
Servo servo;  


byte
    currSwitch,
    lastSwitch;
unsigned long
    timeStart;
bool
    bCheckingSwitch;   
void setup()
{
    servo.attach(9);
      pinMode( LaunchKey, INPUT_PULLUP );
       digitalWrite( Smoke, LOW );
    pinMode( ledPin1, OUTPUT );
    digitalWrite( ledPin1, LOW );
    pinMode( ledPin2, OUTPUT );
    digitalWrite( ledPin2, LOW );
    pinMode( ledPin3, OUTPUT );
    digitalWrite( ledPin3, LOW );
    pinMode( ledPin4, OUTPUT );
    digitalWrite( ledPin4, LOW );
    pinMode( Buzzer, OUTPUT );
    digitalWrite( Buzzer, LOW );
    pinMode( buttonPin, INPUT_PULLUP );
    lastSwitch = digitalRead( buttonPin );
    bCheckingSwitch = false;
   
}//setup

void loop()
{
    //servo opens button access
    
   while (digitalRead(LaunchKey) == HIGH && pos < 92) {
    pos++;
    servo.write(pos);
    delay(15);
  }
   {   
    //read the switch (for simplicity, no debouncing done)
    currSwitch = digitalRead( buttonPin );
    //if the switch is low now and doesn't match its
    //previous reading, it means the switch has changed
    //either unpressed-to-pressed or pressed-to-unpressed
    if( currSwitch != lastSwitch )
    {
        //if low now, the change was unpressed to pressed
        if( currSwitch == LOW )
        {
            //in that case, get the time now to start the
            //5-sec delay...
            timeStart = millis();
            //...indicate we're now timing a press...
            bCheckingSwitch = true;
           
        }//if
        else
        {
            //was a rising edge (button being released)
            //cancel checking the switch timing now since
            //it's not being held hown
            bCheckingSwitch = false;
             digitalWrite( ledPin1, LOW );
             digitalWrite( ledPin2, LOW );
             digitalWrite( ledPin3, LOW );
             digitalWrite( ledPin4, LOW );
             delay (2000); 
             digitalWrite( Buzzer, LOW );
             digitalWrite( Smoke, LOW );
           
        }//else
       
        //and save the
        lastSwitch = currSwitch;
       
    }//if

    //if we haven't seen a rising edge, keep checking the
    //timing
    if( bCheckingSwitch )
    {
        //if the millis count now is 5000 or more higher
        //than it was when the press was detected (timeStart),
        //turn on the LED
        if( (millis() - timeStart ) >= 5000 )
            digitalWrite( ledPin1, HIGH );   
        if( (millis() - timeStart ) >= 15000 )
            digitalWrite( ledPin2, HIGH );
        if( (millis() - timeStart ) >= 25000 )
            digitalWrite( ledPin3, HIGH ); 
        if( (millis() - timeStart ) >= 28000 )
            digitalWrite( ledPin4, HIGH ); 
        if( (millis() - timeStart ) >= 31000 )
            digitalWrite( Buzzer, HIGH );
            digitalWrite( Smoke, HIGH );  //Relay
    }//if
   
}//loop
}

Please, "not working" is not enough information.

The Servo moves to 92 deg, but the Button Does nothing.

The servo should be at 0 then when button pressed Move to 92deg and stay.
If the button is not pressed it returns to 0 deg.
But none of that^ is happening

StrikeforcePC:
If the button is not pressed it returns to 0 deg.

Which part of your code do you think does this?

Ok So thanks for that^ i see what you mean.
It works now, but it won run the rest of the program after the servo.write(92); delay(15);

//Prop Bomb Simple, With SERVO DOOR and Smoke Igniter
#include <Servo.h>

#define buttonPin 10 // analog input pin to use as a digital input
#define ledPin1 3 // digital output pin for LED 1 indicator
#define ledPin2 4 // digital output pin for LED 2 indicator
#define ledPin3 5
#define ledPin4 8
#define Buzzer 12
#define LaunchKey 11
#define Smoke 2 //Smoke is a Relay to a rechargable 3Cell Lipo (which also can run the Chasing Lights). 
Servo servo;
int pos = 0;

byte
currSwitch,
lastSwitch;
unsigned long
timeStart;
bool
bCheckingSwitch;

void setup()
{
  servo.attach(9);
  pinMode( LaunchKey, INPUT_PULLUP );
  lastSwitch = digitalRead( LaunchKey );
  pinMode( Smoke, OUTPUT );
  digitalWrite( Smoke, LOW );
  pinMode( ledPin1, OUTPUT );
  digitalWrite( ledPin1, LOW );
  pinMode( ledPin2, OUTPUT );
  digitalWrite( ledPin2, LOW );
  pinMode( ledPin3, OUTPUT );
  digitalWrite( ledPin3, LOW );
  pinMode( ledPin4, OUTPUT );
  digitalWrite( ledPin4, LOW );
  pinMode( Buzzer, OUTPUT );
  digitalWrite( Buzzer, LOW );
  pinMode( buttonPin, INPUT_PULLUP );
  lastSwitch = digitalRead( buttonPin );
  bCheckingSwitch = false;

}//setup

void loop()
{

  //servo opens button access
  while (digitalRead(LaunchKey) == LOW);
  { servo.write(0);

  while (digitalRead(LaunchKey) == HIGH);
 servo.write(92);
    delay(15);

  }
  
 {
    //read the switch (for simplicity, no debouncing done)
    currSwitch = digitalRead( buttonPin );
    //if the switch is low now and doesn't match its
    //previous reading, it means the switch has changed
    //either unpressed-to-pressed or pressed-to-unpressed
    if ( currSwitch != lastSwitch )
    {
      //if low now, the change was unpressed to pressed
      if ( currSwitch == LOW )
      {
        //in that case, get the time now to start the
        //5-sec delay...
        timeStart = millis();
        //...indicate we're now timing a press...
        bCheckingSwitch = true;

      }//if
      else
      {
        //was a rising edge (button being released)
        //cancel checking the switch timing now since
        //it's not being held hown
        bCheckingSwitch = false;
        digitalWrite( ledPin1, LOW );
        digitalWrite( ledPin2, LOW );
        digitalWrite( ledPin3, LOW );
        digitalWrite( ledPin4, LOW );
        delay (2000);
        digitalWrite( Buzzer, LOW );
        digitalWrite( Smoke, LOW );

      }//else

      //and save the
      lastSwitch = currSwitch;

    }//if

    //if we haven't seen a rising edge, keep checking the
    //timing
    if ( bCheckingSwitch )
    {
      //if the millis count now is 5000 or more higher
      //than it was when the press was detected (timeStart),
      //turn on the LED
      if ( (millis() - timeStart ) >= 5000 )
        digitalWrite( ledPin1, HIGH );
      if ( (millis() - timeStart ) >= 15000 )
        digitalWrite( ledPin2, HIGH );
      if ( (millis() - timeStart ) >= 25000 )
        digitalWrite( ledPin3, HIGH );
      if ( (millis() - timeStart ) >= 28000 )
        digitalWrite( ledPin4, HIGH );
      if ( (millis() - timeStart ) >= 31000 )
        digitalWrite( Buzzer, HIGH );
      digitalWrite( Smoke, HIGH );  //Relay
    }//if

  }//loop

}

That is because you created this endless loop by ending the line with a semicolon:

  while (digitalRead(LaunchKey) == HIGH);

Ok i removed the ;

Now it Moves when the Launch key is pressed but in doesn’t return when UN-pressed.

#include <Servo.h>

#define buttonPin 10 // analog input pin to use as a digital input
#define ledPin1 3 // digital output pin for LED 1 indicator
#define ledPin2 4 // digital output pin for LED 2 indicator
#define ledPin3 5
#define ledPin4 8
#define Buzzer 12
#define LaunchKey 11
#define Smoke 2 //Smoke is a Relay to a rechargable 3Cell Lipo (which also can run the Chasing Lights). 
Servo servo;
int pos = 0;

byte
currSwitch,
lastSwitch;
unsigned long
timeStart;
bool
bCheckingSwitch;

void setup()
{
  servo.attach(9);
  pinMode( LaunchKey, INPUT_PULLUP );
  lastSwitch = digitalRead( LaunchKey );
  pinMode( Smoke, OUTPUT );
  digitalWrite( Smoke, LOW );
  pinMode( ledPin1, OUTPUT );
  digitalWrite( ledPin1, LOW );
  pinMode( ledPin2, OUTPUT );
  digitalWrite( ledPin2, LOW );
  pinMode( ledPin3, OUTPUT );
  digitalWrite( ledPin3, LOW );
  pinMode( ledPin4, OUTPUT );
  digitalWrite( ledPin4, LOW );
  pinMode( Buzzer, OUTPUT );
  digitalWrite( Buzzer, LOW );
  pinMode( buttonPin, INPUT_PULLUP );
  lastSwitch = digitalRead( buttonPin );
  bCheckingSwitch = false;

}//setup

void loop()
{

  //servo opens button access
  while (digitalRead(LaunchKey) == LOW)
{
  servo.write(0);


  while (digitalRead(LaunchKey) == HIGH)
 
  servo.write(92);
    delay(15);
 
}
 
 {
    //read the switch (for simplicity, no debouncing done)
    currSwitch = digitalRead( buttonPin );
    //if the switch is low now and doesn't match its
    //previous reading, it means the switch has changed
    //either unpressed-to-pressed or pressed-to-unpressed
    if ( currSwitch != lastSwitch )
    {
      //if low now, the change was unpressed to pressed
      if ( currSwitch == LOW )
      {
        //in that case, get the time now to start the
        //5-sec delay...
        timeStart = millis();
        //...indicate we're now timing a press...
        bCheckingSwitch = true;

      }//if
      else
      {
        //was a rising edge (button being released)
        //cancel checking the switch timing now since
        //it's not being held hown
        bCheckingSwitch = false;
        digitalWrite( ledPin1, LOW );
        digitalWrite( ledPin2, LOW );
        digitalWrite( ledPin3, LOW );
        digitalWrite( ledPin4, LOW );
        delay (2000);
        digitalWrite( Buzzer, LOW );
        digitalWrite( Smoke, LOW );

      }//else

      //and save the
      lastSwitch = currSwitch;

    }//if

    //if we haven't seen a rising edge, keep checking the
    //timing
    if ( bCheckingSwitch )
    {
      //if the millis count now is 5000 or more higher
      //than it was when the press was detected (timeStart),
      //turn on the LED
      if ( (millis() - timeStart ) >= 5000 )
        digitalWrite( ledPin1, HIGH );
      if ( (millis() - timeStart ) >= 15000 )
        digitalWrite( ledPin2, HIGH );
      if ( (millis() - timeStart ) >= 25000 )
        digitalWrite( ledPin3, HIGH );
      if ( (millis() - timeStart ) >= 28000 )
        digitalWrite( ledPin4, HIGH );
      if ( (millis() - timeStart ) >= 31000 )
        digitalWrite( Buzzer, HIGH );
      digitalWrite( Smoke, HIGH );  //Relay
    }//if

  }//loop
}

Now you're doing this much forever and ever:

  while (digitalRead(LaunchKey) == HIGH)
 
  servo.write(92);

Either you don't understand how to create code blocks using {}, or you don't understand the syntax of ';', or both.

I removed the ";" but now it wont compile/verify.

I am trying to learn as I go, again still very new to this.

thank you for your help.