haha yes

Dependencies:   SB1602E mbed

Fork of Taster_Entprellen by Stefan Kummer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debounceIn.h Source File

debounceIn.h

00001 #include "mbed.h"
00002 
00003 class debounceIn : public DigitalIn
00004 {
00005 public:
00006     /* Liest den entprellten Schattenwert des Pins */
00007     int read(void)
00008     {
00009         return shadow;
00010     }
00011     
00012     /* Stellt ein, wie oft der Pin als 1 bzw. als 0 gelesen werden muss um den Schatten-Zustand zu Schalten */
00013     void setSamples(int i)
00014     {
00015         samples = i;   
00016     }
00017     
00018     void setDebounce_us(int us)
00019     {
00020        ticker.attach_us(callback(this,&debounceIn::cb),us);
00021     }
00022     
00023     /* Konstruktor */
00024     debounceIn(PinName pin ) : DigitalIn(pin)
00025     {   }
00026 protected:
00027     void cb()
00028     {
00029         if(DigitalIn::read())
00030         {
00031             if(counter < samples) counter++;
00032             if(counter == samples) shadow = 1;
00033         }
00034         else
00035         {
00036             if(counter > 0) counter--;
00037             if(counter == 0) shadow = 0;        
00038         }            
00039     }       
00040     int shadow;
00041     int counter;
00042     int samples;
00043     Ticker ticker;
00044 };
00045