N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
sensors/currentsensors.cpp
- Committer:
- bwang
- Date:
- 2015-03-08
- Revision:
- 11:dccbaa9274c5
- Parent:
- currentsensors.cpp@ 6:99ee0ce47fb2
- Child:
- 24:f1ff9c7256b5
File content as of revision 11:dccbaa9274c5:
#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; }