N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
Diff: currentsensors.cpp
- Revision:
- 0:54cf32d35f4d
- Child:
- 1:1f58bdcf2956
diff -r 000000000000 -r 54cf32d35f4d currentsensors.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/currentsensors.cpp Sun Mar 01 06:16:01 2015 +0000 @@ -0,0 +1,16 @@ +#include "includes.h" +#include "classes.h" + +AnalogCurrentSensor::AnalogCurrentSensor(PinName pin, float volts_per_amp) { + _in = new AnalogIn(pin); + _volts_per_amp = volts_per_amp; + Zero(); +} + +void AnalogCurrentSensor::Zero() { + _zero_level = (float) *_in; +} + +float AnalogCurrentSensor::GetCurrent() { + return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp; +} \ No newline at end of file