I have an Arduino Uno. It has two interrupts; int-0(pin 2) and int-1(pin 3). I attached a handler to interrupt 0 and a different one to interrupt 1, using attachInterrupt().
if Interrupt 0 is triggered and it calls its handler,If interrupt 0's handler is still executing when interrupt 1 is triggered, what will happen?
Will interrupt 1 interrupt interrupt 0, or will interrupt 1 wait until interrupt 0's handler is done executing?????
i am doing a small project to count the no.of persons getting IN and OUT of the single door(Assume like a bus door with steps).
this is my code..
// program to count the no.of persons in the room or in bus
int b1 = 2; //sensor1 for boarding checking
int a1 = 3; //sensor2 for boarding checking
int b2 = 4; //sensor3 for alighting checking
int a2 = 5; //sensor4 for alighting checking
volatile int count = 0; //variable to store the count
void setup()
{
pinMode(b1,INPUT);
pinMode(b2,INPUT);
pinMode(a1,INPUT);
pinMode(a2,INPUT);
attachInterrupt(0, Board, LOW);
attachInterrupt(1, Alight, LOW);
Serial.begin(9600);
Serial.println("The occupancy Module is ready");
}
void loop()
{
}
void Board()
{
for(int i=0; i < 1500; i++)
{
if(digitalRead(b2) == LOW)
{
count++;
Serial.print("count = ");
Serial.println(count);
}
}
}
void Alight()
{
for(int j=0; j< 1500; j++)
{
if(digitalRead(a2) == LOW)
{
count--;
Serial.print("count = ");
Serial.println(count);
}
}
}
i wrote a simple code using 4 sensors, and i am using the combination of 2 sensors to make sure the person has get IN or OUT
b1,b2 are for counting the boarded persons,
a1,a2 are for counting the alighted persons,
a1,b1, sensors i am using as interrupt purpose and in the sub routine i am checking for a2 & b2 respectively
i think this code will work for single person boarding and alighting cases..
i have some doubts about this code...
when we are considering the public buses
-> what if two persons (1 boarding and another alighting at same time) passing through the door???
-> how the ISR's will behave????
any one reading post please help me out , give any suggestions to improve my code and which others cases i need to take into consideration...
thanks in advance...