I have a problems with ISR with my YUN. I would like to make an ISR when motion detect with PIR sensor. And after that i would like to start some process with runShellCommand. So here is the problem. If I start with begining the first I detect interrupt with pin2 (attachInterrupt(1, state, CHANGE) and put LEDs HIGH when interrupt it's ok LED13 go HIGH perfect. But when I would like to fire some process when interrupt has occured as I sad before then my YUN doing nothing (even LED13 is not blinking when motion detect). So I think I have some problem with ISR or what? Please help me because I try anything what was on my mind! :-[
What I am doing wrong?
...her is code but not all of it...without function...
#include <Console.h>
#include <Bridge.h>
#include <FileIO.h>
#include <Process.h>
int sensPin = 2;
int ledPin = 13;
volatile int motion;
Process p;
Process date;
void picture(){
Â
p.runShellCommand("fswebcam -r 720x640 /server/static/picture" + time);
  //while(p.running()); //wait till the process ends
 }
void state(){
motion = digitalRead(sensPin);
Â
Â
 if (motion == HIGH) {
  picture();
  digitalWrite(ledPin, HIGH);
 }
 if (motion == LOW) {
 digitalWrite(ledPin, LOW);
 }
Â
}
void setup() {
Â
 Bridge.begin();
 Console.begin();
 FileSystem.begin();
 while(!Console);
Â
 }
 pinMode(sensPin, INPUT);
 digitalWrite(sensPin, LOW);
 pinMode(ledPin, OUTPUT);
Â
 attachInterrupt(1, state, CHANGE);
Â
}
void loop() {
Â
 runTime();
}
Do I have to use flags or what. I think is the problem of ISR execution time. Because if I just fire LED13 is everything works perfect or I would like to do other things like write on SD card in text document etc...perfect. Till then I insert some process then nothing works even LED. So how is work with interrupt if insert a process. Please help!
Why do you (think you) need to do something with a web camera the nanosecond that a slow PIR sensor triggers?
Forget interrupts. Just poll the slow PIR sensor in loop(). Do whatever you need to do when you determine that the sensor state is/became what you want it to be/become.
It checks in loop() not only that there's motion, but that this motion wasn't happening last time through, so it's "new" motion not merely "continuing" motion. It's a good example of checking change in state.
It does a similar thing when there is no motion: if there was motion last time, then the motion has just ended which it alerts, otherwise ignores.
Before I say something, I would like to thank's all of you fog good advices...
But here is the thing, I have already do this loop() code but then I was thinking how to upgrade it with interrupts, so the system will running this functions for definition PIR state and after that make a picture only when external interrupt or motion is detected.
So I was thinking something in this way...
void loop() {
Â
 if (flag){
  sei();Â
  state();
  cli();
 }
}
Without knowing what sets flag, and what state() does, I'd still venture to guess that disabling interrupts after state() ends is a really bad idea.
Interrupts are supposed to be fast. Serial data arrives, and will be lost if not dealt with NOW needs to use interrupts. The clock ticking, which needs to be counted NOW needs to use interrupts.
Turning a slow camera on, in response to a really slow motion detector does NOT need to use interrupts.