I want to work with a DHT sensor, I'm using the Adafruit Library and there is something I can't figure out.
In my project I use a factory pattern to init the DHT sensor, and then pointers to control it.
In the factory I instantiate a new DHT like this :
Factory::addNewDHT(....){
DHT* temp = new DHT(pinNumber,DHT11);
temp->begin();
return temp;
}
Then in main I was not able to readtemperature using pointer->readTemperature();
I read somewhere (but without explication) that it should be static declaration, I tried and it works :).
Does anyone knows why it is like this and how to figure out that this component required a static declaration and some other not?
Dub63:
In my project I use a factory pattern to init the DHT sensor, and then pointers to control it.
I have no idea what a "factory pattern" is and your code is incomplete. But, I'm gonna guess that you're trying to return a local variable that goes out of scope and existence as soon as the function exits. Making it global or local/static prevents that.