Kristian Lauszus
/
BalancingRobotPS3
Code for my balancing robot, controlled with a PS3 controller via bluetooth
Encoder.h
- Committer:
- Lauszus
- Date:
- 2012-03-02
- Revision:
- 4:0b4c320bc948
- Parent:
- 3:c3963f37d597
File content as of revision 4:0b4c320bc948:
#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