I have written arduino code to calculate the platform angle and it works perfectly!
This is a graph made in Processing which is taking the angle calculated by the arduino from the serial port. I am oscillating the board quickly.
I am using the complementary filter approach documented by alot of balancing robots. The actual code is something like:
val = ((((analogRead(xPin)-xZero)/148.48)* 180/3.1415926535897932384626433832795))*-1); //accelerometer angle calculation
valG = valG + ((analogRead(gyroPin) - gZero)*4.8099347014925373134328358208962)/200; //integration of gyro and gyro angle calculation
angle = (val * 0.005) + (valG * 0.995); //complementary filter
valG = angle; //drift correction of gyro integration
I can tell it works as intended, because if i rotate the board flat on the table, the gyro senses it, whilst the accelerometer is still flat, so you see it increase and then decay slowly back to zero, rather like a capacitor discharge curve. This shows the accelerometer correcting the gyro's 'drift'.