Can't get 2 variables to work globally - out of scope error and ThingSpeak error

Board is a WeMos mini

So issue 1: "averageTemp" is not writing to the thingspeak servers properly. Thingspeak is only getting a value of 0. If I take out line 21, then I get a "averageTemp is out of scope" error when compiling on line 130.

Issue 2: after adding the thingspeak sections into the code, "temp" is now showing out of scope on line 164. My brain hurts... I can't figure it out.

Thank you in advance for any assistance!!!

The code is too long to post in the message, so I'm linking it below...

https://drive.google.com/open?id=0B04k9KoKyvzJdFBGTk9uUkxxQTQ

If your code is too long to include please add your .ino file as an attachment.

...R

In the program's main loop{} you have this line:

int averageTemp = total / numReadings; // calculate the averageTemp:

That makes a new local variable called averageTemp. It's not the same as your global averageTemp.

You should have put just:

averageTemp = total / numReadings; // calculate the averageTemp:

Your second point:

On line 99, you initialise a variable float temp.

That line is inside the if statement's {} block, so the variable is local to that block.

This means that your debug code around line 164 can't access it.

If you move that line so it's the first thing in loop like this:

void loop () {
float temp;
...
etc

Then everything that's inside the loop function will be able to use it.

So both your problems were to do with 'variable scope'. You might want to Google that term and do a bit of reading around the subject.

Good luck!

Thank you! That worked a treat!

I'm learning as I go. I'll be sure to do more reading. Thank you again.