D. Damato
/
Exp5_FSRcalibrate
Exp5_FSRcalibrate
main.cpp@1:37707fc10edc, 2011-08-03 (annotated)
- Committer:
- ddamato31
- Date:
- Wed Aug 03 05:57:57 2011 +0000
- Revision:
- 1:37707fc10edc
- Parent:
- 0:a7fdac873af3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ddamato31 | 1:37707fc10edc | 1 | #include "mbed.h" |
ddamato31 | 1:37707fc10edc | 2 | #include "math.h" |
ddamato31 | 1:37707fc10edc | 3 | #include "TextLCD.h" |
ddamato31 | 1:37707fc10edc | 4 | |
ddamato31 | 1:37707fc10edc | 5 | AnalogIn FSR(p17); |
ddamato31 | 1:37707fc10edc | 6 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
ddamato31 | 1:37707fc10edc | 7 | float CalEq; |
ddamato31 | 1:37707fc10edc | 8 | |
ddamato31 | 1:37707fc10edc | 9 | int main() { |
ddamato31 | 1:37707fc10edc | 10 | |
ddamato31 | 1:37707fc10edc | 11 | // Motor RPM average initialization and index |
ddamato31 | 1:37707fc10edc | 12 | double ForceV[10] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; |
ddamato31 | 1:37707fc10edc | 13 | int i; i = 0; |
ddamato31 | 1:37707fc10edc | 14 | |
ddamato31 | 1:37707fc10edc | 15 | while(1) { |
ddamato31 | 1:37707fc10edc | 16 | |
ddamato31 | 1:37707fc10edc | 17 | // Index and reset Motor Average Counter |
ddamato31 | 1:37707fc10edc | 18 | if(i > 9) |
ddamato31 | 1:37707fc10edc | 19 | i = 0; |
ddamato31 | 1:37707fc10edc | 20 | |
ddamato31 | 1:37707fc10edc | 21 | |
ddamato31 | 1:37707fc10edc | 22 | double FSRconst = FSR; |
ddamato31 | 1:37707fc10edc | 23 | ForceV[i] = 6.3713*pow(97.6207, FSRconst) ; // Use AnalogIn (FSR) reading in an equation of Force versus FSR values |
ddamato31 | 1:37707fc10edc | 24 | float ForceAvg = (ForceV[0] + ForceV[1] + ForceV[2] + ForceV[3] + ForceV[4] + ForceV[5] + ForceV[6] + ForceV[7] + ForceV[8] + ForceV[9]) / 10 ; |
ddamato31 | 1:37707fc10edc | 25 | lcd.cls(); |
ddamato31 | 1:37707fc10edc | 26 | lcd.locate(0, 0); |
ddamato31 | 1:37707fc10edc | 27 | lcd.printf("Calibrate FSR"); |
ddamato31 | 1:37707fc10edc | 28 | lcd.locate(0, 1); |
ddamato31 | 1:37707fc10edc | 29 | lcd.printf("V=%f", ForceAvg); |
ddamato31 | 1:37707fc10edc | 30 | ++i; |
ddamato31 | 1:37707fc10edc | 31 | wait(0.25); |
ddamato31 | 1:37707fc10edc | 32 | } |
ddamato31 | 1:37707fc10edc | 33 | } |