Pages: [1]   Go Down
Author Topic: Rising Edge Interrupt  (Read 2405 times)
0 Members and 1 Guest are viewing this topic.
Milwaukee, WI
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//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.
« Last Edit: May 07, 2012, 02:53:29 pm by OmegaNEG1 » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34599
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3072
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 
Code:
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 smiley-wink
Perhaps he'd seen it, if you had used
Code:
code tags ...
« Last Edit: May 07, 2012, 12:01:18 pm by michael_x » Logged

Milwaukee, WI
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. I removed the ; and it works.

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34599
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Milwaukee, WI
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome, thanks again.
Logged

Pages: [1]   Go Up
Jump to: