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: encoder.h
- Revision:
- 0:b89384fab7bf
diff -r 000000000000 -r b89384fab7bf encoder.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/encoder.h Thu Oct 24 02:56:58 2019 +0000
@@ -0,0 +1,33 @@
+//
+// Encoder Class
+//
+// 2019.10.13 ... Originally written by Y.Kuroda
+//
+#ifndef _COUNTER_H
+#define _COUNTER_H
+
+class Encoder {
+ public:
+ Encoder(PinName pin) : _interrupt(pin), _count(0) { // create the InterruptIn on the pin specified to Counter
+ _interrupt.rise(callback(this, &Encoder::increment)); // attach increment function of this counter instance
+ _interrupt.fall(callback(this, &Encoder::increment)); // attach increment function of this counter instance
+ }
+
+ void increment() { _count++; }
+ int read() const { return _count; }
+ int set(int c) { return _count=c; }
+ int reset(){ return set(0); }
+
+ int operator=(int c) { return set(c); }
+// Encoder& operator=(Encoder& c){ return *this; }
+// int operator=(Encoder& c){ return read(); }
+
+ operator int() const { return read(); }
+
+ protected:
+ InterruptIn _interrupt;
+ volatile int _count;
+};
+
+#endif
+