using a button to start the circuit

i need to use a NO button to start my circuit. i want to push the button once and have it run the sketch once then stop
i figured if i set the button as input on pin 12 for example and set up an if statement like....
if (pin12= HIGH);
{// put my sketch here}
but i keep getting errors, am i putting it in the wrong place? i've tried it in void setup and void loop, anyone have any suggestions? should i even be using an "if" here?

Please provide your entire code.

What kind of errors?

if (pin12= HIGH);
{// put my sketch here}

Really? There are three obvious errors in one line of code there (some kind of record), = instead of ==, pin12 instead of digitalRead (pin12), and the blank statement after the if (the ';') Don't you mean

  while (digitalRead (pin12) == LOW)
  {}
  my_stuff () ;

The sketch is always running, you have to wait for the event you are interested in.

All assuming your button is wired up appropriately :wink:

heres my sketch

int led = 13;
int button = 12;

void setup() {

pinMode(led, OUTPUT);

digitalRead(button);
while(digitalRead (button)== HIGH);
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(2000);
digitalWrite(led, LOW);
}

void loop() {
}

heres my error message
whistle2.cpp: In function 'void setup()':
whistle2:29: error: a function-definition is not allowed here before '{' token
whistle2:30: error: expected `}' at end of input

When quoting code, please use the '#' button to put a code tag around your code. It allows us to see the code without additional formating.

In terms of your code, you are missing a close '}' in the setup function, which the compiler is actually telling you about. In C/C+, all open braces ('{') must be matched by a close brace ('}').

int led = 13;
int button = 12;

void setup() {               

  pinMode(led, OUTPUT);


}


void loop() {

  digitalRead(button);
  if(digitalRead (button)== HIGH);    //edited to "if" from "while"
  {   
    digitalWrite(led, HIGH); 
    delay(1000);           
    digitalWrite(led, LOW);
    delay(500);
    digitalWrite(led, HIGH);
    delay(2000);
    digitalWrite(led, LOW);
    digitalRead(button);
  }
}

Compiled but untested.
Do you see the difference? I also added the digital read in the while loop or else you just get stuck inside of it.
You can check that your brackets match by clicking next to them and making sure that it has an opposite.
Also use the auto-format function under tools (or CTRL-T). It helps your code to be more readable.

TeslaIaint:

  while(digitalRead (button)== HIGH);

Hmmm.