toggle switch on->LED on for 5 seconds until toggle switch is reset?

Toggle switch on->LED on for 5 seconds until toggle switch is reset?

Is there any way i can get my arduino to run like this?

So far i have this code but its not working..

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);
delay(5000);
digitalWrite(ledPin, LOW);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Suggestions?
Thanks

There is not call in setup() to activate the internal pull-up resistor. The if test compares the switch state to HIGH, which implies that you are using an external pull-down resistor. Is this right?

Toggle switch on->LED on for 5 seconds until toggle switch is reset?

Turning the LED on for 5 seconds is one thing. "For 5 seconds until toggle switch is reset" is meaningless. What is to happen if the toggle switch is toggled after 3 seconds? What is to happen if the toggle switch is toggled after 10 seconds?

Are you really using a toggle switch, as opposed to a momentary contact switch?

So far i have this code but its not working..

This is whining, plain and simple. What is this code doing? What do you want it to be doing? How does what it is doing differ from what you want it to be doing?

Defining specific, implementable requirements is one of the hardest parts of programming. Writing use cases that can be used to validate the proper implementation of the requirements is a challenge, too. Implementing the requirements, once they are known to be implementable, is trivial (when the hardware supports the requirements, that is). I'm afraid that you need to work on your requirements and use cases.