A preprocessor conditional directive intended to only evaluate as true when compiling for the Arduino Nano 33 BLE board
was also evaluating as true when compiling for any board that didn't define the compared identifiers because undefined
identifiers are replaced with 0 by the C/C++ preprocessor, making them equal.
From the C++11 standard section 16.1, paragraph 4:
> After all replacements due to macro expansion and the defined unary operator
have been performed, all remaining identifiers and keywords 148 , except for true and false, are replaced
with the pp-number 0
The fix is to modify the directive to check whether the macro has been defined.
By cleverly setting _lastreadtime in begin() to make sure that it looks
like the last read was alrady 2000 ms ago, even on startup when millis()
still returns 0, there is no longer a need to keep a separate
firstreading variable, saving a byte of memory and a bit of code.
This allows forcing a read, even if the previous read was less than 2
seconds ago. This is useful in cases where the millis() timer is not
reliable, such as when sleeping. In this case, it is up to the caller to
ensure that at least 2 seconds elapse between calls with force set to
true.
Added constructor parameter to allow for different timing needs. It has
the a default value of 6 which is the original value, so it should be
backwards compatible
Added a basic #ifndef DHT_H to the dht.h file so that if you have a
larger program and want to access the sensor from a different file, you
don't import it twice.