Final Commit

Embed: (wiki syntax)

« Back to documentation index

DebounceIn Class Reference

DebounceIn Class Reference

A digital input with switch debouncing. More...

#include <DebounceIn.h>

Public Member Functions

 DebounceIn (PinName pin, timestamp_t us=1000)
 Create a DebounceIn object connected to the specified pin.
void set_sample_rate (timestamp_t us)
 Set the input sampling rate.
int read (void)
 Read the input, represented as 0 or 1 (int)
 operator int ()
 An operator shorthand for read()
void rise (void(*fptr)(void))
 Attach a function to call when a rising edge occurs on the input.
template<typename T >
void rise (T *tptr, void(T::*mptr)(void))
 Attach a member function to call when a rising edge occurs on the input.
void fall (void(*fptr)(void))
 Attach a function to call when a falling edge occurs on the input.
template<typename T >
void fall (T *tptr, void(T::*mptr)(void))
 Attach a member function to call when a falling edge occurs on the input.

Detailed Description

A digital input with switch debouncing.

Example:

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

 int nrise = 0, nfall = 0;
 void rise() { nrise++; }
 void fall() { nfall++; }

 int main() {
     DebounceIn button(p14);
     button.rise(rise);
     button.fall(fall);
     while (true) {
         printf("nrise=%d, nfall=%d\n", nrise, nfall);
         wait(1);
     }
 }

Definition at line 44 of file DebounceIn.h.


Constructor & Destructor Documentation

DebounceIn ( PinName  pin,
timestamp_t  us = 1000 
)

Create a DebounceIn object connected to the specified pin.

Parameters:
pinDebounceIn pin to connect to
usInput sampling rate (default 1000 microseconds)

Definition at line 19 of file DebounceIn.cpp.


Member Function Documentation

void fall ( void(*)(void)  fptr )

Attach a function to call when a falling edge occurs on the input.

Parameters:
fptrpointer to a void function, or 0 to set as none

Definition at line 50 of file DebounceIn.cpp.

void fall ( T *  tptr,
void(T::*)(void)  mptr 
)

Attach a member function to call when a falling edge occurs on the input.

Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 101 of file DebounceIn.h.

operator int (  )

An operator shorthand for read()

Definition at line 36 of file DebounceIn.cpp.

int read ( void   )

Read the input, represented as 0 or 1 (int)

Returns:
An integer representing the state of the input pin

Definition at line 29 of file DebounceIn.cpp.

void rise ( void(*)(void)  fptr )

Attach a function to call when a rising edge occurs on the input.

Parameters:
fptrpointer to a void function, or 0 to set as none

Definition at line 46 of file DebounceIn.cpp.

void rise ( T *  tptr,
void(T::*)(void)  mptr 
)

Attach a member function to call when a rising edge occurs on the input.

Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 85 of file DebounceIn.h.

void set_sample_rate ( timestamp_t  us )

Set the input sampling rate.

Parameters:
usInput sampling rate

Definition at line 41 of file DebounceIn.cpp.