-
Start by looking at the example code that may or may not be available for the hardware that you didn't tell us about.
-
Use those examples as a guide to write your own code to do what you want.
-
If the code works like you want, you're done.
-
If the code does not behave how you want, post it here with a complete description of how it behaves verses how you want it to behave.
-
People here will look at your code and make suggestions.
-
Use those suggestions to make changes in your code.
-
Go back to #3.