a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

currentsensors.cpp

Committer:
nki
Date:
2015-03-05
Revision:
7:76d6ceb23e0d
Parent:
6:99ee0ce47fb2

File content as of revision 7:76d6ceb23e0d:

#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() {
    _zero_level = (float) *_in;
}

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