Need help with getting a button to work!

Hey we are trying to make a school project with the arduino board, we are making some kind of led light show thingy. but we need a button to start and stop the show and we have tryed alot to make it work but simply nothing have worked for us .. please help... ;D

we need a button that works on 2 digital pins.

int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int timer = 100;
int timer2 = 250;
int timer3 = 500;
int timer4 = 750;
int timer5 = 1000;
int timer6 = 1250;

void setup(){
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
  pinMode(pin4, OUTPUT);
  pinMode(pin5, OUTPUT);
  pinMode(pin6, OUTPUT);
  pinMode(pin7, OUTPUT);
}

void loop() {
//omgang 1
  digitalWrite(pin2, HIGH);
   delay(timer);
   digitalWrite(pin5, HIGH);
   delay(timer);
   digitalWrite(pin6, HIGH);
   delay(timer);
   digitalWrite(pin3, HIGH);
   delay(timer);
   digitalWrite(pin7, HIGH);
   delay(timer);
   digitalWrite(pin4, HIGH);
   delay(timer);
   digitalWrite(pin2, LOW);
   delay(timer);
   digitalWrite(pin5, LOW);
   delay(timer);
   digitalWrite(pin6, LOW);
   delay(timer);
   digitalWrite(pin3, LOW);
   delay(timer);
   digitalWrite(pin7, LOW);
   delay(timer);
   digitalWrite(pin4, LOW);
   delay(timer6);

Your sketch would wait for the on button to be pressed at the start of the loop and you could check if the off button is pressed before each digitalWrite.

If you need to reset from the beginning, you could have the digital writes in a function and return back to loop when the off button is pressed.

pseudocode: lightShow function light each led in sequence if stop button not pressed, if button is pressed then return

loop if start button pressed call lightShow function

I hope that gives you enough to move forward with your school project.

thank for your reply.. but we need to start the show (the part in the void loop() with the push of the button and stop it again with another push on the button.

button is connected to digital pin 11, 13

I got your PM and have posted it here so others can also help you ( I assume you are asking for advice rather than looking for someone to do the schoolwork for you)

What I was suggesting in my previous post was to move all of the code out of loop and put it into a new function that I named lightShow()

You could test this sketch by calling lightShow() from loop. It should work exactly like your current sketch.

To add the button functionality you would need to do two things. First, in loop you would wait for digitalRead to detect that your start button was pressed. You can find tutorials on connecting a pushbutton in various places including the playground. For your application, instead of lighting an LED, you will call the function lightShow() we discussed above.

To get the stop button to work, you need to add some digitalReads in the lightShow function to detect the button and return back to loop when it is pressed.

I suggest you get the start button working first. Then think about how you would add stop button code to the lightShow function. I will be happy to answer more questions on this but please do post your code so I can see how far you are getting.