help with creating function from snippit

  1. Use code tags. The forum software eats some of your code if you don't.

  2. It appears poorly-formatted. Try the auto-formatter in Arduino. Control-T. If it makes a mess of your code then the code was wrong to begin with.

  3. What do you want this code to do?

  4. What does it actually do?