N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
currentsensors.cpp@0:54cf32d35f4d, 2015-03-01 (annotated)
- Committer:
- bwang
- Date:
- Sun Mar 01 06:16:01 2015 +0000
- Revision:
- 0:54cf32d35f4d
- Child:
- 1:1f58bdcf2956
first publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 0:54cf32d35f4d | 1 | #include "includes.h" |
bwang | 0:54cf32d35f4d | 2 | #include "classes.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 | } |