help and advice for my lawgiver project

hi all only got into arduino about a week ago and have already got a fair bit done just stuck on a pice of code at the min for the dna check im trying to pause the code while blue led is lit until red led is lit then continue the code iv tried to use the while code but just locks everything up including the button to unlock as it was

any help and advice would be much appreciated
thanks in advance

 int buttonState = 0;     // variable for reading the pushbutton status  
 int button2State = 0;
 int button3State = 0;
 int count = 0;               // Count the button presses 
 int buttonPressCount = 0;
 int button2PressCount = 0;
 int button3PushCounter = 0;
 int lastButton3State = 0;     // previous state of the button  
 int numberOfLED = 8;
 const int buttonPin = 2;   // the number of the pushbutton pin  
const int button2Pin = 9;   // reload button
const int button3Pin = 10; // dna check 
 const int ledPin1 = 3;   // the number of the LED pin  
 const int ledPin2 = 4;   // the number of the LED pin  
 const int ledPin3 = 5;   // the number of the LED pin  
 const int ledPin4 = 6;   // the number of the LED pin  
 const int ledPin5 = 7;   // the number of the LED pin
 const int ledPin6 = 8;   // the number of the LED pin
 const int ledPin7 = 11;   // blue led dna check
 const int ledPin8 = 12;   // red led dna check 
 // variables will change:  
  
 void setup() {  
  // initialize the LED pin as an output:  
  pinMode(ledPin1, OUTPUT);  
  pinMode(ledPin2, OUTPUT);  
  pinMode(ledPin3, OUTPUT);  
  pinMode(ledPin4, OUTPUT);  
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);  
 // initialize the pushbutton pins as an input:  
  pinMode(buttonPin, INPUT); 
  pinMode(button2Pin, INPUT);
  pinMode(button3Pin, INPUT);
  Serial.begin(9600);
 }  
 void loop() { 
  // read the pushbutton input pin:
  button3State = digitalRead(button3Pin);

  // compare the buttonState to its previous state
  if (button3State != lastButton3State) {
    // if the state has changed, increment the counter
    if (button3State == HIGH) {
      // if the current state is HIGH then the button
      // went from off to on:
      button3PushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(button3PushCounter);
    } else {
      // if the current state is LOW then the button
      // went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButton3State = button3State;

    if (button3PushCounter % 2 == 0) {
   digitalWrite(11, HIGH);
   digitalWrite(12, LOW);
  } else {
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
  }
  
  if (count <= 0)
  {
  digitalWrite(7, HIGH);
  delay(80);
  digitalWrite(6, HIGH);
  delay(80);
  digitalWrite(5, HIGH);
  delay(80);
  digitalWrite(4, HIGH);
  delay(80);
  digitalWrite(3, HIGH);
  }
   // read the state of the pushbutton value: 
 buttonState = digitalRead(buttonPin);
 {
   Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
 }
  button2State = digitalRead(button2Pin);
  if (button2State == HIGH)
  (count = 0)
 // check if the pushbutton is pressed.  
 // if it is, the buttonState is HIGH:
; if (buttonState == HIGH)
 if (count <= 40)
 {
 digitalWrite(8, HIGH);
 delay(20);
 digitalWrite(8, LOW); 
     count ++; 
 // add 1 to the count
 if (count >= 8) 
  
          // turn LED off 
 digitalWrite(ledPin1, LOW); 
   }
   {
  if (count >= 16) 
          // turn LED off  
 digitalWrite(ledPin2, LOW);
 } 
 {
  if (count >= 24)
  // turn LED off 
 digitalWrite(ledPin3, LOW);
 }
 { 
 if (count >= 32)
   // turn LED off
 digitalWrite(ledPin4, LOW);
}
{
  if (count >= 40)
   // turn LED off 
 digitalWrite(ledPin5, LOW);
 }
          // turn LED off


                        
buttonPressCount++;  
delay(100);
 }

lawgiver_light_rail_with_reload.ino (3.52 KB)

 int buttonState = 0;     // variable for reading the pushbutton status  
 int button2State = 0;
 int button3State = 0;
 int count = 0;               // Count the button presses 
 int buttonPressCount = 0;
 int button2PressCount = 0;
 int button3PushCounter = 0;
 int lastButton3State = 0;     // previous state of the button  
 int numberOfLED = 8;
 const int buttonPin = 2;   // the number of the pushbutton pin  
const int button2Pin = 9;   // reload button
const int button3Pin = 10; // dna check 
 const int ledPin1 = 3;   // the number of the LED pin  
 const int ledPin2 = 4;   // the number of the LED pin  
 const int ledPin3 = 5;   // the number of the LED pin  
 const int ledPin4 = 6;   // the number of the LED pin  
 const int ledPin5 = 7;   // the number of the LED pin
 const int ledPin6 = 8;   // the number of the LED pin
 const int ledPin7 = 11;   // blue led dna check
 const int ledPin8 = 12;   // red led dna check

Consistency is a good thing. Numbering ALL variables in a set (like the ledPinX names) is better than numbering just some of them, as in the buttonPin names.

But, numbering variable names is a sure sign that you should be using arrays, instead.

And, why buttonPressCount, button2PressCount and button3PushCounter?

    if (button3PushCounter % 2 == 0) {
   digitalWrite(11, HIGH);
   digitalWrite(12, LOW);
  } else {
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
  }

Am I suppose to remember which pin the blue LED is connected to? Why not give the pins names, so I don't need to remember anything?

  (count = 0)

(What) (purpose) (do) (the) (parentheses) (serve) (?).

Where did the semicolon go?

The turn LED off comments are useless. We KNOW that writing a pin LOW turns it off. The question that the comments should answer is WHY, not WHAT.

Having said all that, I can see no relationship between the issues you are having and the code. You need to describe what the code is doing, using names/numbers from the code, and how that differs from what you want.

First, your description with everything in a single sentence is almost impossible to understand. As far as I can see there are several concepts included in it. A proper description of your project will make it much easier to help you.

It would also be a big help if you explain what the program is intended to do.

And, if you give meaningful names to things it makes a program easier to understand - for example rather than ledpin7 call it blueLEDpin. And it seems a bit crazy to have ledPin7 connected to pin 12.

I suspect the button pins could also be better named.

...R

thanks for the reply's and sorry for the mess i put upon you ie: the code.
I have had a go at rewriting the code as it was and came up with this

int trigerState = 0;     // variable for reading the pushbutton status  
 int reloadState = 0;
 int dnaState = 0;
 int count = 0;               // Count the button presses 
 int trigerPressCount = 0;
 int reloadPressCount = 0;
 int dnaPressCount = 0;
 int lastdnaState = 0;     // previous state of the button  
 int numberOfLED = 8;
const int triger = 2;   // the number of the pushbutton pin  
const int reload = 9;   // reload button
const int dna = 10; // dna check 
 const int redled1 = 3;   // the number of the LED pin  
 const int redled2 = 4;   // the number of the LED pin  
 const int redled3 = 5;   // the number of the LED pin  
 const int redled4 = 6;   // the number of the LED pin  
 const int redled5 = 7;   // the number of the LED pin
 const int flashled = 8;   // the number of the LED pin
 const int blueled = 11;   // blue led dna check
 const int redled = 12;   // red led dna check 
 // variables will change:  
  
 void setup() {  
  // initialize the LED pin as an output:  
  pinMode(redled1, OUTPUT);  
  pinMode(redled2, OUTPUT);  
  pinMode(redled3, OUTPUT);  
  pinMode(redled4, OUTPUT);  
  pinMode(redled5, OUTPUT);
  pinMode(flashled, OUTPUT);
  pinMode(blueled, OUTPUT);
  pinMode(redled, OUTPUT);  
 // initialize the pushbutton pins as an input:  
  pinMode(triger, INPUT); 
  pinMode(reload, INPUT);
  pinMode(dna, INPUT);
  Serial.begin(9600);
 }  
 void loop() { 
  // read the pushbutton input pin:
  dnaState = digitalRead(dna);

  // compare the buttonState to its previous state
  if (dnaState != lastdnaState) {
    // if the state has changed, increment the counter
    if (dnaState == HIGH) {
      // if the current state is HIGH then the button
      // went from off to on:
      dnaPressCount++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(dnaPressCount);
    } else {
      // if the current state is LOW then the button
      // went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state,
  //for next time through the loop
  lastdnaState = dnaState;

    if (dnaPressCount % 2 == 0) {
   digitalWrite(blueled, HIGH);
   digitalWrite(redled, LOW);
  } else {
    digitalWrite(redled, HIGH);
    digitalWrite(blueled, LOW);
  }
  
  if (count <= 0)
  {
  digitalWrite(redled1, HIGH);
  delay(80);
  digitalWrite(redled2, HIGH);
  delay(80);
  digitalWrite(redled3, HIGH);
  delay(80);
  digitalWrite(redled4, HIGH);
  delay(80);
  digitalWrite(redled5, HIGH);
  }
   // read the state of the pushbutton value: 
 trigerState = digitalRead(triger);
 {
   Serial.println(trigerState);
  delay(1);        // delay in between reads for stability
 }
  reloadState = digitalRead(reload);
  if (reloadState == HIGH)
  (count = 0)
 // check if the pushbutton is pressed.  
 // if it is, the buttonState is HIGH:
; if (trigerState == HIGH)
 if (count <= 40)
 {
 digitalWrite(flashled, HIGH);
 delay(20);
 digitalWrite(flashled, LOW); 
     count ++; 
 // add 1 to the count
 if (count >= 8) 
  
          // turn LED off 
 digitalWrite(redled1, LOW); 
   }
   {
  if (count >= 16) 
          // turn LED off  
 digitalWrite(redled2, LOW);
 } 
 {
  if (count >= 24)
  // turn LED off 
 digitalWrite(redled3, LOW);
 }
 { 
 if (count >= 32)
   // turn LED off
 digitalWrite(redled4, LOW);
}
{
  if (count >= 40)
   // turn LED off 
 digitalWrite(redled5, LOW);
 }
          // turn LED off


                        
trigerPressCount++;  
delay(100);
 }

the only reason i didnt use arrays is i cant get my head around them yet i am trying.

the reason the code is the way it is is i took a lot of example code and put it all together to get what i needed. #stilllearning

as for the pause in the code i was talking about

what i have in my head is when the arduino is turned on the blueled will be on and the code paused if you will then by pressing dna blueled off, redled on and unpause if you will ?

what i have in my head is when the arduino is turned on the blueled will be on and the code paused if you will then by pressing dna blueled off,

You are going to have to explain what pressing an LED is supposed to accomplish, and how the Arduino is supposed to know that you are pressing an LED.

You might think that this is picking on you, but, you really need to be able to explain your requirements, if you ever hope to be able to implement them.

I agree with @PaulS. Time spent describing the requirement accurately and in detail will greatly reduce the time taken to write and debug the program.

Write down all the steps that need to happen - one on each line. At this stage just describe things in plain language rather than computer code.

...R
Planning and Implementing a Program

ok
when the arduino is turned on i want the blue led on and nothing else

then when a button is pressed (dna)

the blue led will go off and the red led will come on

then the code can continue

You have used the abbreviation "dna" several times without ever explaining it. Is this project something to do with genetics?

For what you describe you need a WHILE in setup something like this

while( digitalRead(buttonPin) == HIGH) {
}

Assuming the button uses pinMode(buttonPin, INPUT_PULLUP);
this code snippet will run round in a circle endlessly until the button is pressed and reads LOW

...R

Do Not Awaken?
Drugs 'N Alcohol?
Deoxyribo Nucleic Acid?