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.
Fork of HALLFX_ENCODER by
Revision 0:f10558519825, committed 2015-12-08
- Comitter:
- electromotivated
- Date:
- Tue Dec 08 00:09:51 2015 +0000
- Child:
- 1:f28b876f1fe1
- Commit message:
- Upload;
Changed in this revision
| HALLFX_ENCODER.cpp | Show annotated file Show diff for this revision Revisions of this file |
| HALLFX_ENCODER.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HALLFX_ENCODER.cpp Tue Dec 08 00:09:51 2015 +0000
@@ -0,0 +1,20 @@
+#include "HALLFX_ENCODER.h"
+
+HALLFX_ENCODER::HALLFX_ENCODER(PinName enc_in): _enc_in(enc_in){
+ _enc_in.mode(PullUp);
+ // Invoke interrupt on both falling and rising edges
+ _enc_in.fall(this, &HALLFX_ENCODER::callback);
+ _enc_in.rise(this, &HALLFX_ENCODER::callback);
+}
+
+long HALLFX_ENCODER::read(){
+ return count;
+}
+
+void HALLFX_ENCODER::reset(){
+ count = 0;
+}
+
+void HALLFX_ENCODER::callback(){
+ count++;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HALLFX_ENCODER.h Tue Dec 08 00:09:51 2015 +0000
@@ -0,0 +1,38 @@
+#ifndef HALLFX_ENCODER_H
+#define HALLFX_ENCODER_H
+
+/*
+ Basic Encoder Library for Sparkfun's Wheel Encoder Kit
+ Part# ROB-12629.
+*/
+
+#include "mbed.h"
+
+class HALLFX_ENCODER{
+ public:
+ /*
+ Constructor for Encoder objects
+ @param enc_in The mBed pin connected to encoder output
+ */
+ HALLFX_ENCODER(PinName enc_in);
+ /*
+ read() returns total number of counts of the encoder.
+ Count can be +/- and indicates the overall direction,
+ (+): CW (-): CCW
+ @return The toltal number of counts of the encoder.
+ */
+ long read();
+ /*
+ reset() clears the counter to 0.
+ */
+ void reset();
+ private:
+ long count; // Total number of counts since start.
+ InterruptIn _enc_in;// Encoder Input/Interrupt Pin
+ /*
+ Increments/Decrements count on interrrupt.
+ */
+ void callback(); // Interrupt callback function
+};
+
+#endif
\ No newline at end of file
