You should look at the existing libraries and see how they do it, thats the way i learned it, sometimes just altering examples and seeing what happens helps learning
also i think in the arduino playground there is a simple tutorial that can be searched up