Rising Edge Interrupt

I'm trying to set up an interrupt that will act on a rising edge coming from a motion detector to activate an output for a period of time. This is the code that I have so far:




#define LED 13
volatile int flag = LOW;

void setup()
pinMode(LED, OUTPUT);
digitalWrite (LED, LOW);
attachInterrupt(0, light, RISING);

void loop()
  if (flag == HIGH);
    digitalWrite (LED, HIGH);
    digitalWrite (LED, LOW);
    flag = LOW; 

void light()
  flag = HIGH;

I connected the interrupt pin to the ground on the board but my output continually stays on. Any help would be appreciated.

You have not defined an interrupt service routine. That is there is nothing to do when you get an interrupt. See:- http://arduino.cc/it/Reference/AttachInterrupt

if (flag == HIGH);The semicolon is the problem. It ends the if statement. The following block is executed always: 1 sec on, 0 sec off, 1 sec on, 0 sec off, ... You won't see the 0 sec off

Remove the semicolon and don't care about Mike's comment ;) Perhaps he'd seen it, if you had used code tags ...

Thank you. I removed the ; and it works.

I'm a first time poster, what do you mean by code tags?

When posting code, select it then hit the # icon. This puts code tags round the selected item and stops the forum software mangling you code. Go back and modify that first post and see how much better it is.

Awesome, thanks again.