stock mbed AnalogReads current loop closed and working

Dependencies:   mbed

Fork of priustroller_2 by N K

sensors/throttle.cpp

Committer:
bwang
Date:
2016-01-31
Revision:
56:85a26f839af2
Parent:
36:11766b5da6ed

File content as of revision 56:85a26f839af2:

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

Throttle::Throttle(PinName pin, float min, float max) {
    _in = new AnalogVoltageSensor(pin, 1.0f);
    _min = min;
    _max = max;
}

float Throttle::GetThrottle() {
    float v = _in->GetVoltage();
    v = (v - _min) / (_max - _min);
    if (v > 1.0f) return 1.0f;
    if (v < 0.0f) return 0.0f;
    return v;
}