markruys / arduino-DHT

Efficient DHT library for Arduino
Other
163 stars 119 forks source link

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

Open HaleTom opened 5 years ago

HaleTom commented 5 years ago

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?

markruys commented 5 years ago

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.