timerone - single execution

hey folks!
i've searched the whole web to find a solution for a very simple problem, but nothing seems to work. so i just want the following:

press a button -> led goes on for 1 sec -> led turns off.

but i want it to work with a timer interrupt. so i wrote the following code:

#include "TimerOne.h"  
int ledpin=13;

void setup()
{
  pinMode(ledpin, OUTPUT);
  pinMode(11, INPUT);
  Timer1.initialize(1000000);
  Timer1.attachInterrupt(turnoff);
  digitalWrite(ledpin, 0);
}

void turnoff() 
{
  digitalWrite(ledpin, 0);
  Timer1.stop();
}

void loop()    
{
  if (digitalRead(11))
  {
    digitalWrite(ledpin,1);
    Timer1.restart();
  }
}

but when i press the button led1 lights up and thats it - end of story. can someone give me a hint, whats the problem? i have no idea...

tia

Are you sure that you have posted the code that you are using ?

It won't Auto Format - "Too many left curly braces". Final brace missing from the loop() function
Fix that and it won't compile - no semi colon on the digitalWrite line and no brackets round the if condition

my bad. but it doesnt work either =(

eatis:
my bad. but it doesnt work either =(

What is "it" and how doesn't it work? Get your code to compile, then post said code properly formatted (Using the auto-format tool) with CODE tags.

You're not using the internal pullup resistor, so your switch wiring is more complicated than it needs to be. How IS your switch wired?

Have you looked at the blink without delay example? You don't need TimerOne at all. When the switch is pressed, record when that happened, and turn the LED on. Periodically, if the LED is on, see if it is time to turn it off (now minus then greater than or equal on time). If it is, turn the LED off.

@arrch:

"it" is, that the attached interrupt routine doesn't turn off the led after 1 sec as it should do - imho. and i used the code-tags?!

@pauls:

the switch itself is working. it turns the led on, but the ISR doesn't turn it off.. that is my problem. and yes, i've looked at the "blink without delay" example, but i need an interrupt because there is supposed to be code executed while the timer is counting. i use this example to get this interrupt stuff working before messing up the bigger project, where i want to use this.

i need an interrupt because there is supposed to be code executed while the timer is counting.

That's exactly what the BlinkWithoutDelay technique lets you do.

a) only if my loop doesn't take longer than the blink time
b) i still want to know why this interrupt stuff isn't working.

eatis:
when i press the button led1 lights up and thats it - end of story. can someone give me a hint, whats the problem? i have no idea...

What do you expect these two statements to do?

  digitalWrite(ledpin, 0);
  digitalWrite(ledpin, 0);

Timer1.restart() and start() put TimerOne library into the same state as it started, in particular interrupts
are disabled.

Why not initialize the library fully each time you use it (the code in your setup() routine)?

Reading the source to a library is very useful sometimes.

http://forum.arduino.cc/index.php?topic=173451.msg1288299#msg1288299