programming question

Hello, this might seem very simple to most of you, but to learn more about programming Arduino and i took the advice of fellow Arduino member and im trying to take known sketches and change small details to learn about programming. In my code below is the basic button sketch. I am trying to get the LED to light up and stay on even after i press the button once. I don't believe that i can just get rid of the digitalWrite LED low part, because then the led would always be on. Any suggestions?

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

From the sticky "Topic: Read this before posting a programming question"

  1. Getting help on the forum

There are quite a few experienced people on the forum anxious to help you, and help you get as much as you can out of your Arduino. You can help them do that by making helpful posts:

Make an informative subject description

Try to put more effort into your title. Every post in this section of the forum should be a programming question, so your title offers no information on your problem.

On to your question, you want the LED to light up and stay on when the button is pressed once. Removing the digitalWrite low would of course do that.

However you then state that the LED would always be on and that would be a problem for you. How do you want the LED to turn off?
By pressing another button? After a certain amount of time? By powering the Arduino off?

Metallor:
From the sticky "Topic: Read this before posting a programming question"

Try to put more effort into your title. Every post in this section of the forum should be a programming question, so your title offers no information on your problem.

On to your question, you want the LED to light up and stay on when the button is pressed once. Removing the digitalWrite low would of course do that.

However you then state that the LED would always be on and that would be a problem for you. How do you want the LED to turn off?
By pressing another button? After a certain amount of time? By powering the Arduino off?

Thank you for the response, i would say that i want it to turn off after another button press.

See Arduino - Switch

Metallor:
See Arduino - Switch

Thanks

Any particular reason why the debounce value is stored as a long? Surely that value would never have to be big enough to exhaust a regular unsigned integer?

time and debounce should actually both be unsigned long since that is the type that millis() returns. When declaring variables that will be compared with a millis() output you should always use unsigned long. The reason (I think) is to do with when millis() overflows it still work as intended. Someone else can probably give a better explanation.

Metallor:
See Arduino - Switch

It would be well worth re-jigging that to use INPUT_PULLUP instead of that external pulldown. That reverses the logic: will mean looking for a low as a press, but using the built-in resistor is much simpler.

[rant]Why is there no circuit diagram there?[/rant]

There is a photo instead. But yeah, good point about taking advantage of the INPUT_PULLUP.

Metallor:
There is a photo instead.

A photo is just a Fritzy in a suit... It's no substitute for a schematic: it's difficult to make out the resistor's ends in the bread board.

We have to work with what we are given. There are a lot of half assed examples out there.