I have two DHT22 sensors, one for indoor and one for outdoor temperature readings.
I have two ESP8266 boards talking to each other and collating DATA to send to Thingspeak.
Everything works perfectly apart from the following.
I have declared two global variables, float internal_reading; and float external_reading;
In void loop() the indoor DHT22 data is read and displayed using Serial.print.
I then loop out to void read_outdoor() and the exterior DHT22 data is read.
If I Serial.print this value it is correct but when the program returns to void loop() and Serial.print the outdoor variable has reset to 0
I thought that global variables could be changed within the program and the value would be remembered until a reset (power down)?
I suspect there's a problem with the code and it is doing what you wrote and not what you thought/hoped it would do. If you post the code we may be able to tell what is happening.
That is the main critique for having global variables. Anything, anywhere, could look at and alter the value of the variable and it will not be immediately obvious what did it.
Not such an issue with Arduino as we generally write pretty small applications, but if you had a very large codebase, especially with multiple people working on it, then it can be a right pain!
I have several working sketches (TFT Display, Read external sensor, Read API, Get epoch time etc etc) and I have been putting them all together to form one sketch.
One of the problems with copy and paste