winlinvip / SimpleDHT

Simple, Stable and Fast Arduino Temp & Humidity Sensors for DHT11 and DHT22. http://learn.adafruit.com/dht
MIT License
144 stars 61 forks source link

Example code question. #32

Closed macdroid53 closed 2 years ago

macdroid53 commented 5 years ago

Hi,

I am using SimpleDHT and it works fine.

My question is about this snippet in the examples:

void loop() { ... if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000); return; ... }

Why is there a return?

Doesn't this exit loop()? (And wouldn't that return to the somewhere in the boot process of the device?)

Thanks, Mac

ostaquet commented 5 years ago

Hi,

The return statement allows to avoid the output of the results on the Serial. With the return, the loop() method starts again without going through the setup().

KR, Olivier

macdroid53 commented 5 years ago

Does that mean code in loop() following the return does not get executed?

ostaquet commented 5 years ago

Yes, it doesn’t