How to avoid code duplication in a function?

When I wanted to know how to set up my leds I'd asked about using classes and I got yelled at because the leds are not objects, just elements in an array. And since all this code is not an object which I would ever have more than one of, it doesn't seem to make sense to use a class for it either.

It makes enough sense to be useful.
A class can be an object or an interface, if you only have static members you can treat it like a namespace. The advantage being the protected and private areas.