trying to add a pushbutton to my circuit please help me

please can someone help I have the following circuit finally using two shift registers and have freed up so many pins on my uno, thank you to all that have helped me. as I was saying the following circuit I have got working very nicely with 16 leds scrolling from both sides and meeting in the middle then delay on centre led and back to repeat. I want to only have the program one once with a pushbutton on the first press, then I will write a second different sequence for the second push of the button and then also a third sequence on pressing the push button three times then finally a fourth press to turn off. I just don't know how to add a pushbutton into the circuit can anyone help me please.

[code]
//DECLARING SOME VARIABLES

//Pin connected to ST_CP of 74HC595
int latchPin = 9;
//Pin connected to SH_CP of 74HC595
int clockPin = 10;
////Pin connected to DS of 74HC595
int dataPin = 8;


bool registerArray1 = LOW;
bool registerArray2 = LOW;
bool registerArray3 = LOW;
bool registerArray4 = LOW;
bool registerArray5 = LOW;
bool registerArray6 = LOW;
bool registerArray7 = LOW;
bool registerArray8 = LOW;


void setup() {
  Serial.begin ( 115200 );           //Enable the Serial Monitor
  Serial.println ( "Starting.." );   //Write someting
  
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

 

}

void loop() {

  
registerWrite(0,HIGH);// turn far right led on
registerWrite(15,HIGH);// Turn far left led on
delay(50); // wait 50 milliseconds

registerWrite(0,LOW);// Turn first set of leds off
registerWrite(15,LOW);

registerWrite(1, HIGH);// and repeat for LED 4 to 13
registerWrite(14, HIGH);
delay(50);

registerWrite(1, LOW);
registerWrite(14, LOW);

registerWrite(2, HIGH);
registerWrite(13, HIGH);
delay(50);

registerWrite(2, LOW);
registerWrite(13, LOW);

registerWrite(3, HIGH);
registerWrite(12,HIGH);
delay(50);

registerWrite(3, LOW);
registerWrite(12, LOW);

registerWrite(4, HIGH);
registerWrite(11, HIGH);
delay(50);

registerWrite(4, LOW);
registerWrite(11, LOW);

registerWrite(5, HIGH);
registerWrite(10, HIGH);
delay(50);

registerWrite(5, LOW);
registerWrite(10, LOW);

registerWrite(6, HIGH); 
registerWrite(9, HIGH);// central led turn on and delay
delay(50);

registerWrite(6, LOW);
registerWrite(9, LOW);

registerWrite(7, HIGH);
registerWrite(8, HIGH);
delay(50);

registerWrite(7, LOW);
registerWrite(8, LOW);    // turn central led off after delay
delay(50); // then delay off time

registerWrite(8, HIGH);   // turn central led back on for phaser fire
delay(1000);// then hold on for set time as phaser fires

registerWrite(8,LOW);   // then turn off central led

}




void registerWrite(int PIN, bool BOOL){
//Writer to the 8 bit register, PIN - Pin No, BOOL - Status HIGH or LOW

//Update the saved outputs bits
  if (PIN == 1)  {registerArray1 = BOOL;}
  if (PIN == 2)  {registerArray2 = BOOL;}
  if (PIN == 3)  {registerArray3 = BOOL;}
  if (PIN == 4)  {registerArray4 = BOOL;}            
  if (PIN == 5)  {registerArray5 = BOOL;}
  if (PIN == 6)  {registerArray6 = BOOL;}
  if (PIN == 7)  {registerArray7 = BOOL;}
  if (PIN == 8)  {registerArray8 = BOOL;}

//Shift Register the statuses
//Starting with last array so that the first array gets to the first pin.
  if (registerArray8 == HIGH) {shiftOn();} else {shiftOff();}
  if (registerArray7 == HIGH) {shiftOn();} else {shiftOff();}
  if (registerArray6 == HIGH) {shiftOn();} else {shiftOff();}  
  if (registerArray5 == HIGH) {shiftOn();} else {shiftOff();}
  if (registerArray4 == HIGH) {shiftOn();} else {shiftOff();}
  if (registerArray3 == HIGH) {shiftOn();} else {shiftOff();}
  if (registerArray2 == HIGH) {shiftOn();} else {shiftOff();}
  if (registerArray1 == HIGH) {shiftOn();} else {shiftOff();}
   
//Latch Outputs
//This will shift the statuses of to the pins
     digitalWrite(latchPin, HIGH);
     digitalWrite(latchPin, LOW);    
}

  
void shiftOn() {
//ON - Shift with the status ON
//     Serial.println ( "Sent On" );
       digitalWrite(dataPin, HIGH);
       digitalWrite(clockPin, HIGH);
       digitalWrite(clockPin, LOW);
       digitalWrite(dataPin, LOW);
   //  delay(10);     
    }

void shiftOff() {
//OFF - Shift with the status OFF
//     Serial.println ( "Sent Off" );
       digitalWrite(dataPin, LOW);
       digitalWrite(clockPin, HIGH);
       digitalWrite(clockPin, LOW);
       digitalWrite(dataPin, LOW);
   //  delay(10);
    }

[/code]

Don't use uncommon abbreviations. You want to add a peanut butter?

in my world of electrical wholesaling for 35 years and all the electronic circuits I have ever read a 'p/b' has always been denoted to being a pushbutton of some description.

all I am asking is for some help, if you can't or don't want to, I don't want to see comments like that.
just a simple I don't know, but I know a man who can! would of sufficed.

p.s I don't mean to offend anyone, but helpful comments will be greatly appreciated to a newbie in this field

In my forty-odd years of being around electronics (hobby and professional), I've never seen pushbutton abbreviated like that, and was about to ask. Thanks for the clarification.

Have a look at the state change detection example in the IDE (File, Examples, Digital). You will see how to count button pushes and store the current count in a variable. Then you can have a switch case statement that uses the buttonPushCount to select which sequence to run.

Here is a sketch to illustrate what I meant in the previous post. I changed the state change example to work with an active LOW (LOW when pressed) switch. Make a function for each of your sequences to be called by the cases or insert sequence code in the cases.

const int buttonPin = 3;

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState)
  {
    if (buttonState == LOW)
    {
      buttonPushCounter++;
    }
    lastButtonState = buttonState;
  }
  switch (buttonPushCounter)
  {
    case 1:
      // callsequence one
      break;
    case 2:
      // callsequence two
      break;
    case 3:
      // callsequence three
      break;
    case 4:
      //reset button push counter after 3 sequences. Zero is is the idle state
      buttonPushCounter = 0;
      break;
  }
}

still going wrong somewhere added pushbutton circuit and getting error saying registrywrite not declared in this scope, can you help

[code]



//DECLARING SOME VARIABLES

//Pin connected to ST_CP of 74HC595
int latchPin = 9;
//Pin connected to SH_CP of 74HC595
int clockPin = 10;
////Pin connected to DS of 74HC595
int dataPin = 8;


const int buttonPin = 2;

int buttonPushCounter = 0;// counter for the number of button presses
int buttonState = 0;// current state of the button
int lastButtonState = 0;// previous state of the button


bool registerArray1 = LOW;
bool registerArray2 = LOW;
bool registerArray3 = LOW;
bool registerArray4 = LOW;
bool registerArray5 = LOW;
bool registerArray6 = LOW;
bool registerArray7 = LOW;
bool registerArray8 = LOW;


void setup() {
  Serial.begin ( 9600 );           //Enable the Serial Monitor
  Serial.println ( "Starting.." );   //Write someting



  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);

}

void loop() {

buttonState = digitalRead(buttonPin);
 if (buttonState != lastButtonState)
 {
 if (buttonState == LOW)
 {
 buttonPushCounter++;
}
lastButtonState = buttonState;
 }
switch (buttonPushCounter)
{
 case 1:
// callsequence one

    registerWrite(0, HIGH); // turn far right led on
    registerWrite(15, HIGH); // Turn far left led on
    delay(50); // wait 50 milliseconds

    registerWrite(0, LOW); // Turn first set of leds off
    registerWrite(15, LOW);

    registerWrite(1, HIGH);// and repeat for LED 4 to 13
    registerWrite(14, HIGH);
    delay(50);

    registerWrite(1, LOW);
    registerWrite(14, LOW);

    registerWrite(2, HIGH);
    registerWrite(13, HIGH);
    delay(50);

    registerWrite(2, LOW);
    registerWrite(13, LOW);

    registerWrite(3, HIGH);
    registerWrite(12, HIGH);
    delay(50);

    registerWrite(3, LOW);
    registerWrite(12, LOW);

    registerWrite(4, HIGH);
    registerWrite(11, HIGH);
    delay(50);

    registerWrite(4, LOW);
    registerWrite(11, LOW);

    registerWrite(5, HIGH);
    registerWrite(10, HIGH);
    delay(50);

    registerWrite(5, LOW);
    registerWrite(10, LOW);

    registerWrite(6, HIGH);
    registerWrite(9, HIGH);
    delay(50);

    registerWrite(6, LOW);
    registerWrite(9, LOW);

    registerWrite(7, HIGH);
    registerWrite(8, HIGH);
    delay(50);

    registerWrite(7, LOW);
    registerWrite(8, LOW);    // turn central led off after delay
    delay(50); // then delay off time

    registerWrite(8, HIGH);   // turn central led back on for phaser fire
    delay(1000);// then hold on for set time as phaser fires

    registerWrite(8, LOW);  // then turn off central led
break;

case 2:
 // callsequence two
break;
case 3:
 // callsequence three
break;
 case 4:
//reset button push counter after 3 sequences. Zero is is the idle state
buttonPushCounter = 0;
break;
 
}

  void registerWrite(int PIN, bool BOOL) {
    //Writer to the 8 bit register, PIN - Pin No, BOOL - Status HIGH or LOW

    //Update the saved outputs bits
    if (PIN == 1)  {
      registerArray1 = BOOL;
    }
    if (PIN == 2)  {
      registerArray2 = BOOL;
    }
    if (PIN == 3)  {
      registerArray3 = BOOL;
    }
    if (PIN == 4)  {
      registerArray4 = BOOL;
    }
    if (PIN == 5)  {
      registerArray5 = BOOL;
    }
    if (PIN == 6)  {
      registerArray6 = BOOL;
    }
    if (PIN == 7)  {
      registerArray7 = BOOL;
    }
    if (PIN == 8)  {
      registerArray8 = BOOL;
    }

    //Shift Register the statuses
    //Starting with last array so that the first array gets to the first pin.
    if (registerArray8 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }
    if (registerArray7 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }
    if (registerArray6 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }
    if (registerArray5 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }
    if (registerArray4 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }
    if (registerArray3 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }
    if (registerArray2 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }
    if (registerArray1 == HIGH) {
      shiftOn();
    } else {
      shiftOff();
    }

    //Latch Outputs
    //This will shift the statuses of to the pins
    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);
  }


  void shiftOn() {
    //ON - Shift with the status ON
    //     Serial.println ( "Sent On" );
    digitalWrite(dataPin, HIGH);
    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
    digitalWrite(dataPin, LOW);
    //  delay(10);
  }

  void shiftOff() {
    //OFF - Shift with the status OFF
    //     Serial.println ( "Sent Off" );
    digitalWrite(dataPin, LOW);
    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
    digitalWrite(dataPin, LOW);
    //  delay(10);
  }

[/code]

  buttonPushCounter = 0;
  break; 
  }

} // <<<<    this curly bracket is missing

  void registerWrite(int PIN, bool BOOL) {

You are missing the curly bracket to close the loop() function. Insert a curly bracket where I have indicated.

In the future, please include the full text of the error message (in code tags). There is information in the message that may make the error easier to fix.

so sorry for not including the error message but that has corrected it, the pushbutton is working on the first press but it must take at least 20 presses after using different times between presses before it recognises the second push. am I doing something wrong?

You have a lot of delay()s in the sketch. The Arduino can't read the switch while in a delay(). So if the sketch spends 90% of the time in delay there's only a 10% chance of reading the switch, so to speak. A responsive program can't use blocking functions like delay(). Perhaps the several things at a time sketch will help to understand how to use millis() for timing and avoid delay().

thank you for the reply, but because the delays are inside the sequence being sent to the shift registers , (I don't know how or even if you can change that into millis once it has been sent to the shift registers) I didn't think it would slow the main program. I thought it might be due to bouncing??

If your switches are wired input to ground with the internal pullups enabled you can add a 0.1uf cap across the switch to prevent bounce and eliminate the possibility of that being the cause, although I really think the delays are responsible. Once the sequence starts, the switch is not read until the sequence finishes. Then the switch is read at the top of loop() and the program goes right into another sequence. The time window for switch reading is pretty narrow.

digin.jpg

right understand that diagram thank you very much will try that in the morning, only one more question I have put the sequences inside each 'case' and it runs the first sequence/case over and over again in the loop until it recognises the second press of the button. how can I modify the code so the sequence only runs once on each press?

regards
neil

Have a flag for each sequence. Only run the sequence if the flag is false. If the flag is false, run the sequence and at the end of the sequence set the flag to true. When all sequences have run, set all the flags back to false.