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

Revision:
11:24b34deae975
Parent:
10:2502b829d452
--- a/mRotaryEncoder.cpp	Fri Feb 26 20:18:57 2016 +0000
+++ b/mRotaryEncoder.cpp	Tue Mar 03 12:20:55 2020 +0000
@@ -2,7 +2,7 @@
 #include "mRotaryEncoder.h"
 
 
-mRotaryEncoder::mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode, int debounceTime_us) {
+mRotaryEncoder::mRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode, int debounceTime_us, int detectRise, int detectFall) {
     m_pinA = new PinDetect(pinA);                      // interrrupts on pinA
     m_pinB = new DigitalIn(pinB);                      // only digitalIn for pinB
 
@@ -11,8 +11,12 @@
     m_pinB->mode(pullMode);
 
     // attach interrrupts on pinA
-    m_pinA->attach_asserted(this, &mRotaryEncoder::rise);
-    m_pinA->attach_deasserted(this, &mRotaryEncoder::fall);
+    if (detectRise != 0){
+        m_pinA->attach_asserted(this, &mRotaryEncoder::rise);
+    }
+    if (detectFall != 0){
+        m_pinA->attach_deasserted(this, &mRotaryEncoder::fall);
+    }
     
     //start sampling pinA
     m_pinA->setSampleFrequency(debounceTime_us);                  // Start timers an Defaults debounce time.