Have you though about passing an array of pin numbers instead of a single pin number to the function?