N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
currentsensors.cpp
- Committer:
- nki
- Date:
- 2015-03-04
- Revision:
- 6:99ee0ce47fb2
- Parent:
- 1:1f58bdcf2956
- Child:
- 7:76d6ceb23e0d
File content as of revision 6:99ee0ce47fb2:
#include "includes.h" #include "sensors.h" AnalogCurrentSensor::AnalogCurrentSensor(PinName pin, float volts_per_amp) { _in = new AnalogIn(pin); _volts_per_amp = volts_per_amp; Zero(); } void AnalogCurrentSensor::Zero() { float mean = 0; for(int i = 1; i<=1000; i++){ mean = 0.1f*((float) *_in) + 0.9f*mean; } _zero_level = mean; } float AnalogCurrentSensor::GetCurrent() { return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp; }