Programming before "setup"

Was searching for a program to run a temp sensor and found this.

No comments, can somebody explain why there is so much programming before the void setup().

I do not even know what to search for to get a better understanding.
pinOut is the name he assigns to Pin10.

I know that “double” is a variable type, so Temp is a variable name.

What is all the calculation in aid of?

#include <math.h>

int pinOut = 10;

double Thermistor(int RawADC) {
double Temp;
Temp = log(10000.0*((1024.0/RawADC-1)));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;
Temp = (Temp * 9.0)/ 5.0 + 32.0;
return Temp;
}

void setup() {

Steinhart-Hart equation.

No comments, can somebody explain why there is so much programming before the void setup().

this is just code to define a function called Thermistor which is returning a number formatted as double

you will call that function probably in the loop().

You can move that function definition after setup or the loop function and it will still work.

Using double with an Arduino is a waste of time because both float and double are the same size.

So he has actually written his own function??

What do I search for to get more info on this topic?

Why do you want to write your own function?

:confused:

Thanks Thanks Thanks.

Why do you want to write your own function?

Multiple possible reasons such as :

So that it does exactly what you want
You can’t find one to do what you want
There isn’t a function to do what you want
etc

You write a function for many reasons. One of them is if you want to use it from several places in your main program flow. It's a lot easier having a function call rather than having to copy all that code into everywhere you want to use it. Another reason is just for neatness - it makes the main flow easier to read if it calls a few (well-named) functions instead of being a mass of code lines.

There are already a lot of basic functions provided for you but there are plenty of reasons to make your own specialised functions.

Steve

you probably need to get a C or C++ programming book and read about how to structure programs

What is the terminology when you write your own function?

Want to go and read in the "Resources/Refrences" section.

https://www.arduino.cc/en/Reference/FunctionDeclaration

Another reason for writing your own functions is that it can be given meaningful names so that reading and understanding your code is easier and you can also write small, discrete programs to test the functions.

Have a look at Planning and Implementing an Arduino program

Should your own functions be of general use in more than one project you can even put them in a library and include the library when any of the functions is required.

Thanks to all, getting bit above my head.

Let me first get to grips with writing one's own function. At least understanding it.

:)

jo_6466: /En utilisant un DHT22 avec sa bibliothèque, le relevé de la température et de l'humidité se fait avec une facilité déconcertante avec une très bonne précision/

@jo_6466 - what's this irrelevant contribution?

also please go read the rules on how to post code on the forum, will help you later on...

HermanJFourie: Thanks to all, getting bit above my head.

Let me first get to grips with writing one's own function. At least understanding it.

:)

read the link in post #9 - that will get you going