Go Down

Topic: Rising Edge Interrupt (Read 2596 times) previous topic - next topic

OmegaNEG1

May 07, 2012, 06:48 pm Last Edit: May 07, 2012, 09:53 pm by OmegaNEG1 Reason: 1
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:
Code: [Select]

//EWagner

//5/7/2002

//

#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);
   delay(1000);
   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.

Grumpy_Mike

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

michael_x

#2
May 07, 2012, 06:57 pm Last Edit: May 07, 2012, 07:01 pm by michael_x Reason: 1
Code: [Select]
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: [Select]
code tags ...

OmegaNEG1

Thank you. I removed the ; and it works.

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

Grumpy_Mike

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.

OmegaNEG1


Go Up