Debouncer Class Referenceabstract

The Debouce class. Just the deboucing code separated from all harware. More...

`#include <Bounce2.h>`

Inheritance diagram for Debouncer:

## Public Member Functions

| Debouncer ()
| Create an instance of the Debounce class. More...
void | interval (uint16_t interval_millis)
| Sets the debounce interval in milliseconds. More...
bool | update ()
| Updates the pin's state. More...
bool | read () const
| Returns the pin's state (HIGH or LOW). More...
bool | fell () const
| Returns true if pin signal transitions from high to low.
bool | rose () const
| Returns true if pin signal transitions from low to high.
bool | changed () const
| Returns true if the state changed on last update. More...
unsigned long | currentDuration () const
| Returns the duration in milliseconds of the current state. More...
unsigned long | previousDuration () const
| Returns the duration in milliseconds of the previous state. More...
unsigned long | duration ()
| DEPRECATED (i.e. do not use). Renamed currentDuration(). More...

## Protected Member Functions

void | begin ()
virtual bool | readCurrentState ()=0

## Protected Attributes

unsigned long | previous_millis
uint16_t | interval_millis
uint8_t | state
unsigned long | stateChangeLastTime
unsigned long | durationOfPreviousState

## Detailed Description

The Debouce class. Just the deboucing code separated from all harware.

## Constructor & Destructor Documentation

## Debouncer()

Debouncer::Debouncer | ( |  | ) |

Create an instance of the Debounce class.

## Member Function Documentation

## changed()

bool Debouncer::changed | ( |  | ) | const

inline

Returns true if the state changed on last update.

Returns
  True if the state changed on last update. Otherwise, returns false.

## currentDuration()

unsigned long Debouncer::currentDuration | ( |  | ) | const

Returns the duration in milliseconds of the current state.

Is reset to 0 once the pin rises ( rose() ) or falls ( fell() ).

Returns
  The duration in milliseconds (unsigned long) of the current state.

## duration()

unsigned long Debouncer::duration | ( |  | ) |

inline

DEPRECATED (i.e. do not use). Renamed currentDuration().

This member function is DEPRECATED will be removed next major version. DO NOT USE IT. USE currentDuration() INSTEAD. It was renamed to avoid confusion with previousDuration().

Returns
  The duration in milliseconds (unsigned long) of the current state.

## interval()

void Debouncer::interval | ( | uint16_t | interval_millis | ) |

Sets the debounce interval in milliseconds.

Parameters

  interval_millis | The interval time in milliseconds.

## previousDuration()

unsigned long Debouncer::previousDuration | ( |  | ) | const

Returns the duration in milliseconds of the previous state.

Takes the values of duration() once the pin changes state.

Returns
  The duration in milliseconds (unsigned long) of the previous state.

## read()

bool Debouncer::read | ( |  | ) | const

Returns the pin's state (HIGH or LOW).

Returns
  HIGH or LOW.

## update()

bool Debouncer::update | ( |  | ) |

Updates the pin's state.

Because Bounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your loop()). Only call update() once per loop().

Returns
  True if the pin changed state.

The documentation for this class was generated from the following files:

- src/Bounce2.h
- src/Bounce2.cpp