Extends DigitalIn to DebounceIn to provide mechanical switch debouncing.

Dependents:   AVC_20110423 Pushbutton_NoBounce_Demo FinalTime AVC_2012 ... more

Embed: (wiki syntax)

« Back to documentation index

DebounceIn Class Reference

DebounceIn Class Reference

DebounceIn adds mechanical switch debouncing to DigitialIn. More...

#include <DebounceIn.h>

Public Member Functions

void set_debounce_us (int i)
 set_debounce_us
void set_samples (int i)
 set_samples
int read (void)
 read
 operator int ()
 operator int()
 DebounceIn (PinName pin)
 Constructor.

Detailed Description

DebounceIn adds mechanical switch debouncing to DigitialIn.

Example:

 #include "mbed.h"
 #include "DebounceIn.h"

 DebounceIn  d(p5);
 DigitialOut led1(LED1);
 DigitialOut led2(LED2);

 int main() {
     while(1) {
         led1 = d;
         led2 = d.read();
     }
 }
See also:
set_debounce_us() To change the sampling frequency.
set_samples() To alter the number of samples.

Users of this library may also be interested in PinDetect library:-

See also:
http://mbed.org/users/AjK/libraries/PinDetect/latest

This example shows one input displayed by two outputs. The input is debounced by the default 10ms.

Definition at line 57 of file DebounceIn.h.


Constructor & Destructor Documentation

DebounceIn ( PinName  pin )

Constructor.

Parameters:
PinNamepin The pin to assign as an input.

Definition at line 95 of file DebounceIn.h.


Member Function Documentation

operator int (  )

operator int()

Read the value of the debounced pin.

Definition at line 88 of file DebounceIn.h.

int read ( void   )

read

Read the value of the debounced pin.

Definition at line 81 of file DebounceIn.h.

void set_debounce_us ( int  i )

set_debounce_us

Sets the debounce sample period time in microseconds, default is 1000 (1ms)

Parameters:
inti The debounce sample period time to set.

Definition at line 66 of file DebounceIn.h.

void set_samples ( int  i )

set_samples

Defines the number of samples before switching the shadow definition of the pin.

Parameters:
inti The number of samples.

Definition at line 75 of file DebounceIn.h.