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.
Diff: src/encoders.cpp
- Revision:
- 0:88c60458332e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/encoders.cpp Thu Nov 08 06:38:19 2018 +0000 @@ -0,0 +1,38 @@ +#include "encoders.h" +#include "pins.h" +#include "globals.h" +#include "mbed.h" +#include "QEI.h" + +/*** + * Assignment 2 + * + * Import the QEI in order to have functioning encoders. + ***/ +QEI wheel_R(ENC_RF, ENC_RB, NC, 624, QEI::X4_ENCODING); +QEI wheel_L(ENC_LF, ENC_LB, NC, 624, QEI::X4_ENCODING); + +/////// +// Encoder class implementation +/////// + +Encoder::Encoder() { + reset(); +} + +void Encoder::reset() volatile { + wheel_R.reset(); + wheel_L.reset(); +} + +int Encoder::getPulsesR() volatile { + return wheel_R.getPulses(); +} + +int Encoder::getPulsesL() volatile { + return wheel_L.getPulses(); +} + +void Encoder::printValues() volatile { + pc.printf("R: %d\tL: %d\n", getPulsesR(), getPulsesL()); +}