
LCD Accelerometer with interrupt fault
calibrate.cpp@0:298e8a54dc2d, 2010-05-12 (annotated)
- Committer:
- Aubs
- Date:
- Wed May 12 20:40:52 2010 +0000
- Revision:
- 0:298e8a54dc2d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Aubs | 0:298e8a54dc2d | 1 | #include "header.h" |
Aubs | 0:298e8a54dc2d | 2 | |
Aubs | 0:298e8a54dc2d | 3 | extern float Xcal; |
Aubs | 0:298e8a54dc2d | 4 | extern float Ycal; |
Aubs | 0:298e8a54dc2d | 5 | extern float Zcal; |
Aubs | 0:298e8a54dc2d | 6 | extern int i; |
Aubs | 0:298e8a54dc2d | 7 | extern float per_old; |
Aubs | 0:298e8a54dc2d | 8 | extern float per_new; |
Aubs | 0:298e8a54dc2d | 9 | extern float sumx; |
Aubs | 0:298e8a54dc2d | 10 | extern float sumy; |
Aubs | 0:298e8a54dc2d | 11 | extern float sumz; |
Aubs | 0:298e8a54dc2d | 12 | extern float Xoff; |
Aubs | 0:298e8a54dc2d | 13 | extern float Yoff; |
Aubs | 0:298e8a54dc2d | 14 | extern float Zoff; |
Aubs | 0:298e8a54dc2d | 15 | |
Aubs | 0:298e8a54dc2d | 16 | void calibrate(void){ |
Aubs | 0:298e8a54dc2d | 17 | while (1){ |
Aubs | 0:298e8a54dc2d | 18 | lcd.locate(1,11); lcd.printf("Press Select to Confirm"); |
Aubs | 0:298e8a54dc2d | 19 | |
Aubs | 0:298e8a54dc2d | 20 | sumx=0; |
Aubs | 0:298e8a54dc2d | 21 | sumy=0; |
Aubs | 0:298e8a54dc2d | 22 | sumz=0; |
Aubs | 0:298e8a54dc2d | 23 | |
Aubs | 0:298e8a54dc2d | 24 | for(i=0; i<199; i++) { |
Aubs | 0:298e8a54dc2d | 25 | Xcal=((Xcal)*(per_old))+((acc.x())*(per_new)); |
Aubs | 0:298e8a54dc2d | 26 | Ycal=((Ycal)*(per_old))+((acc.y())*(per_new)); |
Aubs | 0:298e8a54dc2d | 27 | Zcal=((Zcal)*(per_old))+((acc.z())*(per_new)); |
Aubs | 0:298e8a54dc2d | 28 | lcd.locate(1,9); lcd.printf("Calibrate"); lcd.printf("%i",(200-i)); |
Aubs | 0:298e8a54dc2d | 29 | sumx += Xcal; |
Aubs | 0:298e8a54dc2d | 30 | sumy += Ycal; |
Aubs | 0:298e8a54dc2d | 31 | sumz += Zcal; |
Aubs | 0:298e8a54dc2d | 32 | |
Aubs | 0:298e8a54dc2d | 33 | } |
Aubs | 0:298e8a54dc2d | 34 | Xoff=0-(sumx/200); |
Aubs | 0:298e8a54dc2d | 35 | Yoff=0-(sumy/200); |
Aubs | 0:298e8a54dc2d | 36 | Zoff=1-(sumz/200); |
Aubs | 0:298e8a54dc2d | 37 | |
Aubs | 0:298e8a54dc2d | 38 | lcd.locate(1,1); lcd.printf("X="); lcd.printf("%0.5f",Xoff); |
Aubs | 0:298e8a54dc2d | 39 | lcd.locate(1,3); lcd.printf("Y="); lcd.printf("%0.5f",Yoff); |
Aubs | 0:298e8a54dc2d | 40 | lcd.locate(1,5); lcd.printf("Z="); lcd.printf("%0.5f",Zoff); |
Aubs | 0:298e8a54dc2d | 41 | |
Aubs | 0:298e8a54dc2d | 42 | but2.fall(&menuscreen); |
Aubs | 0:298e8a54dc2d | 43 | } |
Aubs | 0:298e8a54dc2d | 44 | |
Aubs | 0:298e8a54dc2d | 45 | } |