Replacing PulseIn() Function

Hi I have been using the pulseIn() function for a dust sensor I purchased. I have now purchased another one and realised you cant use the pulseIn() function twice in the same sketch.

I found out that I can use External Interrupts which I found on this site: Three Ways To Read A PWM Signal With Arduino | BenRipley.com

I have used there code example but changed it a bit because I want to measure from HIGH to LOW so the pulse in function to do this would be:

pulseIn(3, LOW);

so I wrote this code to replace that function:

volatile int pwm_value = 0;
volatile int prev_time = 0;

void setup()
{
    Serial.begin(9600);
    attachInterrupt(0, falling, FALLING);
}

void loop() 
{}

void rising() {
  attachInterrupt(0, falling, FALLING);
  pwm_value = micros()-prev_time;
  Serial.println(pwm_value);
}
 
void falling() {
  attachInterrupt(0, rising, RISING);
  prev_time = micros();
}

I just used the example from the link above. I never get anything printed to my Serial Monitor which is odd because I would have though even if it wasnt working I would see something.

I tried adding Serial.print("hello"); to the setup and that didnt print either so I am not sure if I have done something wrong.

The "hello" message is now printing I just added while(!Serial); so now it waits until it loads. The attachInterrupt still isnt printing anything so these issues werent related.

UPDATE

I have got it printing to the serial monitor. The fix was using digitalPinToInterrupt(3) like so attachInterrupt(digitalPinToInterrupt(3), falling, FALLING);

I then decided to run the pulseIn() function and the attachInterrupt function one after another and the results arent anywhere near each other. I know they wont be identical but they are way off.

Here is the new code that I have written:

volatile int pwm_value = 0;
volatile int prev_time = 0;
int pin_large = 3;

void setup()
{
    Serial.begin(9600);
    pinMode(pin_large,INPUT);
}

void loop() 
{
    long duration_large = pulseIn(pin_large, LOW);
    attachInterrupt(digitalPinToInterrupt(3), falling, FALLING);

    Serial.println(pwm_value);
    Serial.println(duration_large);
    Serial.println("");

    delay(6000);
}

void rising() {
  pwm_value = micros()-prev_time;
}
 
void falling() {
  attachInterrupt(digitalPinToInterrupt(3), rising, RISING);
  prev_time = micros();
}

Does this look right? I am going to keep working on it so I will keep you updated.

The pwm_value variable sometimes prints minus numbers so there is clearly something wrong.

volatile int prev_time = 0;

  prev_time = micros();

You might want to look up what micros() returns. Hint: It is NOT an int.