self balance robot code for dead spot help needed

The other approach you could take is to vary the speed and direction of the motor according to how far the 'bot is away from the balance point. With that approach the speed naturally drops down to zero as the 'bot reaches the balance point and you don't need an explicit dead band. This approach is IMO likely to give better behaviour, assuming that your sensors and overall feedback algorithm is sufficient to achieve a balance at all - which I'm not convinced about.
[/quote]
yes you were right about all..
thank you very much for the advice.
I like the idea of using feed back. so I thought I could use 2 rotary encoder from scroll wheels in mice. hmmmm there is a extended shaft comming off the back of the gearbox opposite of the output shaft that I could attach the encoders too.
and thank you very much for the code example. I didn't know if I was doing the neg number (i.e. -50) correctly.
ps. the servo output is 0 for level and appx +600 for appx 45* angle on the y axis in one direction and -600 for appx. 45* angle the other direction on the same axis. <---- I hope you can appreciate those specs? lol

Before I get too much into this code that may not work at all, what would be a better approach?
(assuming that I do use the rotary encoders or change out to servo's modded for continuous rotation)
would it be good to use the accelerometer output (xVal) as a variable to directly change motor speed and direction? i.e.
if xVal <= 0
backward
if xVal >= 0
foward
and use xval (with a little math) to change pwm?
wow, this is starting to get a little complicated...
"I'm not scared" and the yoda reply" you will be.... , you will be"
I am just trying to pick brains here... thanks all.