Having trouble working out delay with button

Hey guys. So I'm working on a smaller project but have ran into an issue that I assume is software. Whenever I press a button to start a sequence, it does not start immediately. I actually have to hold the button for a various amount of time. The circuit is pretty much just like the button example, but here is the code.

const int buttonPin2 = 3;

const int buttonPin = 2; const int ledPin = 13; const int ledPin2 = 12;

int buttonState2 = 0; int buttonState = 0; void setup() {

pinMode(ledPin2, OUTPUT); pinMode(ledPin, OUTPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin, INPUT);

//led timer pinMode(31, OUTPUT); pinMode(33, OUTPUT); pinMode(35, OUTPUT); pinMode(37, OUTPUT); pinMode(39, OUTPUT); pinMode(41, OUTPUT); pinMode(43, OUTPUT); pinMode(45, OUTPUT); pinMode(47, OUTPUT); pinMode(49, OUTPUT);

//arming timer pinMode(22, OUTPUT); pinMode(24, OUTPUT); pinMode(26, OUTPUT);

//alarm pinMode(53, OUTPUT); }

void loop() {

digitalWrite(22, HIGH); delay(1000); digitalWrite(24, HIGH); delay(1000); digitalWrite(26, HIGH);

// read the state of the pushbutton value: buttonState = digitalRead(buttonPin); buttonState2 = digitalRead(buttonPin2); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH:

if (buttonState == HIGH) { digitalWrite(13, HIGH);

//arming timer end

//led timer start digitalWrite(31, HIGH); delay(1000);

digitalWrite(33, HIGH); delay(1000);

digitalWrite(35, HIGH); delay(1000);

digitalWrite(37, HIGH); delay(1000);

digitalWrite(39, HIGH); delay(1000);

digitalWrite(41, HIGH); delay(1000);

digitalWrite(43, HIGH); delay(1000);

digitalWrite(45, HIGH); delay(1000);

digitalWrite(47, HIGH); delay(1000);

digitalWrite(49, HIGH);

//alarm digitalWrite(53, HIGH); }

if (buttonState2 == HIGH) {

digitalWrite (53, HIGH);

} else {

} }

Is my problem software? Or should I take it to hardware? Thanks guys, I appreciate the help.

 digitalWrite(22, HIGH);
  delay(1000); 
  digitalWrite(24, HIGH);
  delay(1000);
  digitalWrite(26, HIGH);

A delay() function will always cause a problem. It actually freezes your sketch until it's waited the time it says there.

So when you press the button, and it has to do the delays first, it can take some time (maximum 2 seconds in your sketch) before it is read.

BTW: you don't have a piece that turns the digital writes off, is that right?

O, and next time post your code in a code box... it's better and people won't complain... And take a look at the "blinkwithoutdelay" example to get rid of those delays!

The demo several things at a time is an extended example of BWoD.

...R