bance:
and simplify the code further.
I try (and probably fail frequently) to make my functions as self contained as possible so that they can be copied into a simpler test sketch and should work.
However, in a contradiction of that, I prefer to use global (rather than static local) variables in Arduino code because I can see more clearly how I am using the limited memory. So if I copy a function to another sketch I probably also have to copy the relevant global variables as well.
In general I would not use global variables in a PC program where there is almost unlimited memory (well, how long would it take me to type 2 gigabytes of rubbish?).
...R