a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Revision:
11:dccbaa9274c5
Parent:
6:99ee0ce47fb2
Child:
24:f1ff9c7256b5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensors/currentsensors.cpp	Sun Mar 08 08:37:38 2015 +0000
@@ -0,0 +1,20 @@
+#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() {
+    float mean = 0;
+    for(int i = 1; i<=1000; i++){
+        mean = 0.1f*((float) *_in) + 0.9f*mean;
+    }
+    _zero_level = mean;
+}
+
+float AnalogCurrentSensor::GetCurrent() {
+    return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp;
+}
\ No newline at end of file