https://github.com/johndavid400/Segbot
You will need to use the code that corresponds to the gyro/accelerometer you are using.
If you are using the sensors from my book, use this:
https://github.com/johndavid400/Segbot/blob/master/v1/Seg_bot_v1_2.pde
Otherwise, I have written code for 2 other sets of sensors and mostly done with a 3rd set from Radio Shack/Parralax.
Let me know if you have questions.
jd