sf
batter.cpp@0:e1658d625afc, 2016-09-27 (annotated)
- Committer:
- floatlei
- Date:
- Tue Sep 27 09:41:52 2016 +0000
- Revision:
- 0:e1658d625afc
sf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
floatlei | 0:e1658d625afc | 1 | #include "batter.h" |
floatlei | 0:e1658d625afc | 2 | |
floatlei | 0:e1658d625afc | 3 | //batter |
floatlei | 0:e1658d625afc | 4 | AnalogIn batter_volt(PA_3); |
floatlei | 0:e1658d625afc | 5 | DigitalOut batter_free(PB_5); |
floatlei | 0:e1658d625afc | 6 | |
floatlei | 0:e1658d625afc | 7 | BatterVol::BatterVol() |
floatlei | 0:e1658d625afc | 8 | { |
floatlei | 0:e1658d625afc | 9 | |
floatlei | 0:e1658d625afc | 10 | batter_free=1; |
floatlei | 0:e1658d625afc | 11 | } |
floatlei | 0:e1658d625afc | 12 | |
floatlei | 0:e1658d625afc | 13 | unsigned short BatterVol::detect(void) |
floatlei | 0:e1658d625afc | 14 | { |
floatlei | 0:e1658d625afc | 15 | float batval; |
floatlei | 0:e1658d625afc | 16 | unsigned short bata; |
floatlei | 0:e1658d625afc | 17 | |
floatlei | 0:e1658d625afc | 18 | batter_free=0; |
floatlei | 0:e1658d625afc | 19 | wait(5); |
floatlei | 0:e1658d625afc | 20 | batter_free=1; |
floatlei | 0:e1658d625afc | 21 | wait(3); |
floatlei | 0:e1658d625afc | 22 | |
floatlei | 0:e1658d625afc | 23 | batval=batter_volt.read(); |
floatlei | 0:e1658d625afc | 24 | batval*=4.17; //3*7.1/5.1 |
floatlei | 0:e1658d625afc | 25 | |
floatlei | 0:e1658d625afc | 26 | bata=(unsigned short)(batval*100); |
floatlei | 0:e1658d625afc | 27 | |
floatlei | 0:e1658d625afc | 28 | return bata; |
floatlei | 0:e1658d625afc | 29 | } |