How to use 'arkhipenko/TaskScheduler' for pulseIn() function?

Hi all,

I have some problem about using ‘arkhipenko/TaskScheduler’ for pulseIn() function.

At first, my project use DSM501A (dust sensor) with NodeMCU ESP8266. Actually, in my project has more sensor beside this one.

I use ‘arkhipenko/TaskScheduler’ library for each sensor measurement. Other sensor can easy understand to use TaskSchedule, except DSM501A. Because DSM501A use pulseIn() function for keep summary time of Low Signal.

Below code is one part of operation. It use normal process.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(DUST_SENSOR_DIGITAL_PIN_PM10, INPUT);
  pinMode(DUST_SENSOR_DIGITAL_PIN_PM25, INPUT);

  // wait 60s for DSM501 to warm up
  for (int i = 1; i <= 60; i++)
  {
    delay(1000); // 1s
    Serial.print(i);
    Serial.println(" s (wait 60s for DSM501 to warm up)");
  }

  Serial.println("Ready!");

  AQI.starttime = millis();
  
  timer.setInterval(sampletime_ms);
}

void loop() {
  AQI.lowpulseoccupancyPM10 += pulseIn(DUST_SENSOR_DIGITAL_PIN_PM10, LOW);
  AQI.lowpulseoccupancyPM25 += pulseIn(DUST_SENSOR_DIGITAL_PIN_PM25, LOW);

  if (timer.isReady()) {
    updateAQI();
    timer.reset();
  }
}

refer: Calculate the Air Quality Index (IAQ, IQA) with a DSM501 on Arduino or ESP8266 • DIY Projects

Notice, It keep pulseIn() LOW duration signal every loop() function, until 5 minutes, then it calculate AQI value from keep pulseIn() LOW duration.

I cannot imagine, how to convert code to use ‘arkhipenko/TaskScheduler’. :roll_eyes:

Please advise me.

Thank you in advance.

arkhipenko/TaskScheduler Github

https://github.com/arkhipenko/TaskScheduler

arkhipenko/TaskScheduler Wiki

RV mineirin

Thank you very much.