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: encoders.cpp
- Revision:
- 0:7a97ebb833eb
diff -r 000000000000 -r 7a97ebb833eb encoders.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/encoders.cpp Sun May 05 00:02:11 2019 +0000
@@ -0,0 +1,46 @@
+#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_RB, ENC_RF, 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 {
+ m_countR = 0;
+ m_countL = 0;
+ wheel_R.reset();
+ wheel_L.reset();
+}
+
+void Encoder::update() volatile {
+ m_countR = wheel_R.getPulses();
+ m_countL = wheel_L.getPulses();
+}
+
+int Encoder::right() volatile {
+ return wheel_R.getPulses();
+}
+
+int Encoder::left() volatile {
+ return wheel_L.getPulses();
+}
+
+void Encoder::printValues() volatile {
+// Serial pc(TX, RX);
+ pc.printf("R: %d\tL: %d\n", right(), left());
+}