Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of analoghalls5_5 by
Diff: sensors/throttle.cpp
- Revision:
- 11:dccbaa9274c5
- Parent:
- 10:b4abecccec7a
diff -r b4abecccec7a -r dccbaa9274c5 sensors/throttle.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensors/throttle.cpp Sun Mar 08 08:37:38 2015 +0000 @@ -0,0 +1,16 @@ +#include "includes.h" +#include "sensors.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; +} \ No newline at end of file