a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

sensors/currentsensors.cpp

Committer:
nki
Date:
2015-05-21
Revision:
55:f102d271e808
Parent:
33:e7b132029bae

File content as of revision 55:f102d271e808:

#include "includes.h"
#include "sensors.h"

AnalogCurrentSensor::AnalogCurrentSensor(PinName pin, float volts_per_amp) {
    _in = new AnalogIn(pin);
    _volts_per_amp = volts_per_amp;
    wait_us(100000);
    Zero();
}

void AnalogCurrentSensor::Zero() {
    float mean = 0;
    for(int i = 0; i < 1000; i++){
        mean += (float) *_in;
    }
    _zero_level = mean / 1000;
}

float AnalogCurrentSensor::GetCurrent() {
    return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp;
}