N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
currentsensors.cpp@7:76d6ceb23e0d, 2015-03-05 (annotated)
- Committer:
- nki
- Date:
- Thu Mar 05 11:02:54 2015 +0000
- Revision:
- 7:76d6ceb23e0d
- Parent:
- 6:99ee0ce47fb2
uh what;
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() { |
nki | 7:76d6ceb23e0d | 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 | } |