Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
weight/weight.cpp@4:5213bee8158e, 2014-04-14 (annotated)
- Committer:
- redplam
- Date:
- Mon Apr 14 02:15:32 2014 +0000
- Revision:
- 4:5213bee8158e
- Parent:
- 3:0ef2ced1f02d
myproject;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
redplam | 3:0ef2ced1f02d | 1 | #include "mbed.h" |
redplam | 3:0ef2ced1f02d | 2 | #include "weight.h" |
redplam | 3:0ef2ced1f02d | 3 | static const int MAX_DATAPOINTS=500; |
redplam | 3:0ef2ced1f02d | 4 | static const float MAX_ADC_VALUE=65535; |
redplam | 3:0ef2ced1f02d | 5 | |
redplam | 3:0ef2ced1f02d | 6 | unsigned short current_weight_1=0; |
redplam | 3:0ef2ced1f02d | 7 | unsigned int current_weight_1_int=0; |
redplam | 3:0ef2ced1f02d | 8 | unsigned short CMA_weight1=0; |
redplam | 3:0ef2ced1f02d | 9 | unsigned int dead_load=32500; |
redplam | 3:0ef2ced1f02d | 10 | float weight1=0; |
redplam | 3:0ef2ced1f02d | 11 | void read_weight(){ |
redplam | 3:0ef2ced1f02d | 12 | int count =0; |
redplam | 3:0ef2ced1f02d | 13 | while(count<MAX_DATAPOINTS){ |
redplam | 3:0ef2ced1f02d | 14 | |
redplam | 3:0ef2ced1f02d | 15 | current_weight_1 = weight_sense1.read_u16(); |
redplam | 3:0ef2ced1f02d | 16 | |
redplam | 3:0ef2ced1f02d | 17 | CMA_weight1 = (current_weight_1 + (count*CMA_weight1))/(count+1); |
redplam | 3:0ef2ced1f02d | 18 | wait_ms(5); |
redplam | 3:0ef2ced1f02d | 19 | count++; |
redplam | 3:0ef2ced1f02d | 20 | } |
redplam | 3:0ef2ced1f02d | 21 | CMA_weight1=CMA_weight1-dead_load; |
redplam | 3:0ef2ced1f02d | 22 | } |
redplam | 3:0ef2ced1f02d | 23 | |
redplam | 3:0ef2ced1f02d | 24 | void calc_weight(){ |
redplam | 3:0ef2ced1f02d | 25 | weight1 = (float)CMA_weight1/MAX_ADC_VALUE; |
redplam | 3:0ef2ced1f02d | 26 | printf("%d -> weightsensor=%4.4f\n\r",CMA_weight1,weight1); |
redplam | 3:0ef2ced1f02d | 27 | } |