InterruptIn style DigitalIn debounced with callbacks for pin state change and pin state hold.

Fork of PinDetect by Andy K

Revision:
2:cb3afc45028b
Parent:
1:611a8f5ac65c
Child:
3:8d7f44cc5347
diff -r 611a8f5ac65c -r cb3afc45028b PinDetect.h
--- a/PinDetect.h	Thu Jan 13 09:53:26 2011 +0000
+++ b/PinDetect.h	Thu Jan 13 11:09:22 2011 +0000
@@ -166,6 +166,8 @@
     
 public:
 
+    friend class Ticker;
+    
     PinDetect() { error("You must supply a PinName"); }
 
     /** PinDetect constructor
@@ -202,6 +204,7 @@
      */
     void setSampleFrequency(int i = PINDETECT_SAMPLE_PERIOD) { 
         _sampleTime = i; 
+        _prevState  = _in->read();        
         _ticker->attach_us( this, &PinDetect::isr, _sampleTime );
     }
     
@@ -449,7 +452,8 @@
      * Read the value of the pin being sampled.
      */
     operator int() { return _in->read(); }
-    
+
+protected:    
     /** The Ticker periodic callback function
      */
     void isr(void) {