a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Revision:
33:e7b132029bae
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensors/currentsensors.cpp	Mon Mar 16 03:09:48 2015 +0000
@@ -0,0 +1,21 @@
+#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;
+}
\ No newline at end of file