Help needed to merge two void loops

The 2nd part is just another function, fn().
Add it to the bottom of the file of the first part, and call it as needed.

Then add the parts after the function definition to the bottom of your current loop(), and debug from there.