Right now it's in the loop "sub routine". So create one that looks like loop, but has a different name and copy the code into it. That's the easy answer, but I get the feeling you're going to run into issues with trying to do other things in the loop because that code is blocking. If that's a problem, you'll need to learn about writing non blocking code using millis() and state machines. The former of which is demonstrated in the blink without delay example.
Do you know what a subroutine does?
From the sound of your question I think that you think it will execute a piece of code at the same time as other code is running. That is not a subroutine but a thread.
The Arduino is a single threaded machine as are all the other single code processors so it you want to make it look like it is doing two or more things at once you need to implement what is known as a state machine.
Get rid of all the delays and rewrite your code in the style of the blink without delay example.
Grumpy_Mike:
Do you know what a subroutine does?
From the sound of your question I think that you think it will execute a piece of code at the same time as other code is running. That is not a subroutine but a thread.
The Arduino is a single threaded machine as are all the other single code processors so it you want to make it look like it is doing two or more things at once you need to implement what is known as a state machine.
Get rid of all the delays and rewrite your code in the style of the blink without delay example.
No sorry, I do understand the difference, in this case I want a sub to keep code tidy that's all When this sub is called no other work will be done, as this is a warning state