N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
currentsensors.cpp@1:1f58bdcf2956, 2015-03-01 (annotated)
- Committer:
- bwang
- Date:
- Sun Mar 01 10:51:28 2015 +0000
- Revision:
- 1:1f58bdcf2956
- Parent:
- 0:54cf32d35f4d
- Child:
- 6:99ee0ce47fb2
moar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 0:54cf32d35f4d | 1 | #include "includes.h" |
bwang | 1:1f58bdcf2956 | 2 | #include "sensors.h" |
bwang | 0:54cf32d35f4d | 3 | |
bwang | 0:54cf32d35f4d | 4 | AnalogCurrentSensor::AnalogCurrentSensor(PinName pin, float volts_per_amp) { |
bwang | 0:54cf32d35f4d | 5 | _in = new AnalogIn(pin); |
bwang | 0:54cf32d35f4d | 6 | _volts_per_amp = volts_per_amp; |
bwang | 0:54cf32d35f4d | 7 | Zero(); |
bwang | 0:54cf32d35f4d | 8 | } |
bwang | 0:54cf32d35f4d | 9 | |
bwang | 0:54cf32d35f4d | 10 | void AnalogCurrentSensor::Zero() { |
bwang | 0:54cf32d35f4d | 11 | _zero_level = (float) *_in; |
bwang | 0:54cf32d35f4d | 12 | } |
bwang | 0:54cf32d35f4d | 13 | |
bwang | 0:54cf32d35f4d | 14 | float AnalogCurrentSensor::GetCurrent() { |
bwang | 0:54cf32d35f4d | 15 | return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp; |
bwang | 0:54cf32d35f4d | 16 | } |