Class mRotaryEncoder for mechanical incremental rotary encoders with pushbuttons. Use debouncing and callback-functions for rotation and pressing of button. This version is for old mbed. New version for mbed-os see https://os.mbed.com/users/charly/code/mRotaryEncoder-os/

Dependencies:   PinDetect

Dependents:   SimplePIDBot FinalProgram VS1053Player SPK-DVIMXR ... more

Files at this revision

API Documentation at this revision

Comitter:
charly
Date:
Tue Feb 01 19:43:46 2011 +0000
Parent:
1:bb7b4e631dff
Child:
3:39c2fc4482be
Commit message:
Changed InterruptIn for switch to PinDetect

Changed in this revision

PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
mRotaryEncoder.cpp Show annotated file Show diff for this revision Revisions of this file
mRotaryEncoder.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Tue Feb 01 19:43:46 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- a/mRotaryEncoder.cpp	Mon Nov 29 21:38:17 2010 +0000
+++ b/mRotaryEncoder.cpp	Tue Feb 01 19:43:46 2011 +0000
@@ -15,8 +15,11 @@
     m_pinA->fall(this, &mRotaryEncoder::fall);
 
     // Switch on pinSW
-    m_pinSW = new InterruptIn(pinSW);                 // interrupt on press switch
+    m_pinSW = new PinDetect(pinSW);                 // interrupt on press switch
     m_pinSW->mode(pullMode);
+    
+    m_pinSW->setSampleFrequency(); // Defaults to 20ms.
+
 
     m_position = 0;
 
--- a/mRotaryEncoder.h	Mon Nov 29 21:38:17 2010 +0000
+++ b/mRotaryEncoder.h	Tue Feb 01 19:43:46 2011 +0000
@@ -2,6 +2,7 @@
 #define MROTENC_H_INCLUDED
 
 #include "mbed.h"
+#include "PinDetect.h"
 
 
 /** This Class handles a rotary encoder with mechanical switches and an integrated pushbutton
@@ -77,7 +78,7 @@
     * @param fptr Pointer to callback-function
     */
     void attachSW(void (*fptr)(void)) {
-        m_pinSW->fall(fptr);
+        m_pinSW->attach_asserted(fptr);
     }
 
     template<typename T>
@@ -125,7 +126,8 @@
 
     int             m_debounceTime_us;
 
-    InterruptIn     *m_pinSW;
+    //InterruptIn     *m_pinSW;
+    PinDetect       *m_pinSW;
 
     void rise(void);
     void fall(void);