Code for my balancing robot, controlled with a PS3 controller via bluetooth

Dependencies:   mbed

Revision:
3:c3963f37d597
Child:
4:0b4c320bc948
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Encoder.h	Sun Feb 26 13:11:10 2012 +0000
@@ -0,0 +1,26 @@
+#ifndef _encoder_h_
+#define _encoder_h_
+
+class Encoder {
+public:
+    Encoder(PinName pinA, PinName pinB) : _HallSensorA(pinA), _HallSensorB(pinB) {
+        _counter = 0;
+        _HallSensorA.rise(this, &Encoder::EncodeA);
+    }
+    long read() {
+        return _counter;
+    }
+private:
+    volatile long _counter;
+    InterruptIn _HallSensorA;
+    DigitalIn _HallSensorB;
+
+    void EncodeA() {
+        if (_HallSensorB.read())
+            _counter++;
+        else
+            _counter--;
+    }
+};
+
+#endif
\ No newline at end of file