When should i use a function or not ? for example

You should use the timers instead of delays, that is good.

Just make lots of functions. It is not less efficient to have many functions.