a common cathode seven segment display library

The jump from copy-n-paste code to classes might be too long...

I think you could start improving by learning how to use arrays. Also, avoid using single letter variables, use more meaningful names, e.g. pin_a, pin_b, ... pin_dp.