Need help with if else program

I have been trying to write a simple if else program to control an led. How it should have worked is that when a button is pressed, the led turns off for 1 secon, then turns off. What ends up happening is that the led flashes on and off, 1 second off and a quick flash on, unless the button is held down, then it turns off, and goes back to its flashing pattern when the button is no longer held down. I don't know what is causing this problem, I have tried updating my arduino program to the latest version, and I have tried changing the code. It has no problems uploading to t he board, or compiling. if you have had this problem before or know how to fix it please let me know. Thank you for taking the time to read this post.

Please, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.
Put your sketch between the code tags [code][/code]

How it should have worked is that when a button is pressed, the led turns off for 1 secon, then turns off.

I assume that one of those offs should be an on.

As well as the sketch a description of how the switch and LED are wired would be helpful.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.

Thanks.. Tom... :)

without seeing your code it's pretty hard to give advice. That said, these posts did help me when getting started: https://www.arduino.cc/en/Tutorial/Button

You could have a bouncing issue (though it doesn't sound like it): https://www.arduino.cc/en/Tutorial/Debounce

Button state change example: https://www.arduino.cc/en/Tutorial/StateChangeDetection?from=Tutorial.ButtonStateChange

here's my code:

int switchState = 0;
void setup(){
  pinMode(6,OUTPUT);
  pinMode(7,INPUT);
}
void loop(){
  switchState = digitalRead(7);
  if (switchState == LOW) {
    digitalWrite(6, HIGH);
  }
  else{
    digitalWrite(6, LOW);
    delay(1000);
  }
}

How are the switch and the led wired?

pinMode(7,INPUT ) ; Try: pinMode(7,INPUT_PULLUP ) ;

Always show us an image of the wiring and a schematic.

|500x436

.

If you check the Arduino reference site for the digitalpin tutorial (https://www.arduino.cc/en/Tutorial/DigitalPins) you should see that the return for the pin if there is no input is undefined. The return from the function you are using could change giving you a different result without you appearing to have made any changes (assuming you have no defined input)

In order to make sure it is defined you need to do as LarryD has suggested internally or else externally as shown in his diagram.