Unikron:
Ok..
How could I "translate" this to a function?
And call it from the loop?
The Arduino IDE uses C++ but that is really a superset of C. Try reading this book to find out how functions etc work.
http://www.dipmat.univpm.it/~demeio/public/the_c_programming_language_2.pdf
Then write very simple programs that just have print statements in the loop and in your own functions then build up to the final code. That way you will know how everything works.