Writing Libraries

Did you try the tutorial on the official Arduino website?