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.
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.
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.
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/