I do not really grasp the volatile. I understand that it uses different memory. but how tu use it?
No, it doesn't use different memory.
Instead, it forces the compiler to generate code to read the memory (or register) whenever it is referenced, otherwise, the compiler could simply "optimise-out" the reference.
Imagine you had some code in a loop in "loop", inspecting a variable that is changed in an interrupt.
while (globalVariable == 0) {
// do nothing, wait for "globalVariable" to be non-zero
}
Here, imagine "globalVariable" is a global variable in-scope, declared simply "int globalVariable;"
In the code above, there's nothing in the body of the while loop that changes "globalVariable", so the compiler could, legitimately, interpret the "while" as an "if", simply examining the value of "globalVariable" just once, and making a yes/no decision just once.
The volatile qualifier forces the compiler to form a proper loop, because the variable could be changed by an outside influence, like an interrupt.