Interrupts , mega

Hello ,

I have three sensors , I need to know which sensor reads the alarm first . Is it possible to use interrupts?

I used the standard code from the library and wrote a code for three inputs , but every time alarm happens , all three outputs are active . Is it possible ,the first reading sensor blocks others two ? so I could locate the alarm .

thanks

Is there anything you think you should be telling us?

Sure
here the code for two sensors
When the sound happens around the sens1 it triggers the LED , but after sens2 triggers other interrupt. I want only one led on , I could see where the sound comes from.

#define LED1 10
#define LED2 13
#define SENS1 2// mic1
#define SENS2 3//mic2

void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED1, 0); // LED off
digitalWrite(LED2, 0); // LED off
pinMode(SENS1, INPUT);
pinMode(SENS2, INPUT);
attachInterrupt(0, ISR0, RISING);
attachInterrupt(1, ISR1, RISING);
}

void loop() {
digitalWrite(LED1, 0); // LED off//no sound
digitalWrite(LED2, 0); // LED off // no sound
}
void myDelay(int x) {
for(unsigned int i=0; i<=x; i++)
{
delayMicroseconds(1000);
}
}
void ISR0()// sound on left side
{
digitalWrite(LED1, 1); // LED on
myDelay(290);
}
void ISR1(){ // sound on right side
digitalWrite(LED2, 1); // LED on
myDelay(290);

}

Why are you delaying 291 milliseconds in interrupt context?

Can we expect code tags?

its more the 29ms , around 290 ms , the led is up and its visible , but the problem is , they are both up , one starts a bit early and after the delay other , I want only one LED on , can you help with that ?
thanks

sp. "around 291 ms"

Light one LED, and prevent the other from lighting.

I don't really know why you're using interrupts at all.

It would actually be easier without interrupts. Read both inputs and check to see which one has a LOW to HIGH transition. That would be the first one so light up that LED and ignore the other. Then do it all over again.

I did it, reading ports without interrupts, but there is a time between reading the ports, I thought the interrupts will be much faster, that why.

How I prevent other Led from lighting up?
That was the question.

How I prevent other Led from lighting up?

Perhaps something like this.

void ISR0()// sound on left side
{
  if (digitalRead(LED2) == 0)
  {
    digitalWrite(LED1, 1); // LED on
  }
}

void ISR1()// sound on right side
{
  if (digitalRead(LED1) == 0)
  {
    digitalWrite(LED2, 1); // LED on
  }
}

I'm not sure how long you want to leave the led's on and then clear them for the next event.

Thank you very much for your help I will try it tomorrow

I tried it , and it does work ! something to learn ! thanks I hope I will be able to finish the code for three sensors .