arduino-DHT icon indicating copy to clipboard operation
arduino-DHT copied to clipboard

Why test startTime - lastReadTime < 1999 and not < 2000 for DHT22

Open HaleTom opened this issue 6 years ago • 1 comments

Why are you testing for < 1999 rather than < 2000 here:

  if ( (unsigned long)(startTime - lastReadTime) < (model == DHT11 ? 999L : 1999L) ) {
    return;
  }

Are you assuming that the overhead of calling the function will be 1ms, such that the duty cycle of 2000ms is maintained?

HaleTom avatar Feb 11 '19 12:02 HaleTom

Correct. It's actually more a safety check so that you don't poll the sensor too often. Thinking of it, I now would write the code such that you track the actual sample rate and and check it's not being called at a faster pace.

markruys avatar Feb 11 '19 13:02 markruys