
LCD Accelerometer with interrupt fault
Diff: calibrate.cpp
- Revision:
- 0:298e8a54dc2d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/calibrate.cpp Wed May 12 20:40:52 2010 +0000 @@ -0,0 +1,45 @@ +#include "header.h" + +extern float Xcal; +extern float Ycal; +extern float Zcal; +extern int i; +extern float per_old; +extern float per_new; +extern float sumx; +extern float sumy; +extern float sumz; +extern float Xoff; +extern float Yoff; +extern float Zoff; + +void calibrate(void){ + while (1){ + lcd.locate(1,11); lcd.printf("Press Select to Confirm"); + + sumx=0; + sumy=0; + sumz=0; + + for(i=0; i<199; i++) { + Xcal=((Xcal)*(per_old))+((acc.x())*(per_new)); + Ycal=((Ycal)*(per_old))+((acc.y())*(per_new)); + Zcal=((Zcal)*(per_old))+((acc.z())*(per_new)); + lcd.locate(1,9); lcd.printf("Calibrate"); lcd.printf("%i",(200-i)); + sumx += Xcal; + sumy += Ycal; + sumz += Zcal; + + } + Xoff=0-(sumx/200); + Yoff=0-(sumy/200); + Zoff=1-(sumz/200); + + lcd.locate(1,1); lcd.printf("X="); lcd.printf("%0.5f",Xoff); + lcd.locate(1,3); lcd.printf("Y="); lcd.printf("%0.5f",Yoff); + lcd.locate(1,5); lcd.printf("Z="); lcd.printf("%0.5f",Zoff); + + but2.fall(&menuscreen); + } + +} \ No newline at end of file