Bounce3
A poll based debounce library with a small RAM footprint
Public Member Functions | List of all members
Bounce3 Class Reference

An object that debounces a single GPIO. More...

#include <Bounce3.h>

Public Member Functions

 Bounce3 (uint8_t pin, uint8_t mode, uint8_t pin_mode)
 
 Bounce3 (uint8_t pin, uint8_t mode)
 
 Bounce3 (uint8_t pin)
 
bool poll (uint32_t ts, uint8_t val)
 Update the button state. More...
 
bool poll (void)
 
uint8_t pressed (void)
 Check if the button was pressed this loop. More...
 
bool held (void)
 
uint32_t heldFor (uint32_t millis)
 
uint32_t heldFor (void)
 
uint32_t released (void)
 
bool changed (void)
 

Detailed Description

An object that debounces a single GPIO.

Constructor & Destructor Documentation

◆ Bounce3() [1/3]

Bounce3::Bounce3 ( uint8_t  pin,
uint8_t  mode,
uint8_t  pin_mode 
)
Parameters
pinWhich digital pin to read
modeA bitwise-or of config values (default: B3_MODE_ONESHOT | B3_ACTIVE_LOW)
pin_modeIf you wish to specify pinMode (default: INPUT_PULLUP)

◆ Bounce3() [2/3]

Bounce3::Bounce3 ( uint8_t  pin,
uint8_t  mode 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ Bounce3() [3/3]

Bounce3::Bounce3 ( uint8_t  pin)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Member Function Documentation

◆ poll() [1/2]

bool Bounce3::poll ( uint32_t  ts,
uint8_t  val 
)

Update the button state.

Parameters
tsThe timestamp to use. (default: millis())
valThe pin reading. (default: digitalRead(pin))
Returns
true, if the button state changes

◆ poll() [2/2]

bool Bounce3::poll ( void  )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ pressed()

uint8_t Bounce3::pressed ( void  )

Check if the button was pressed this loop.

If the button was not pressed, the function returns zero. A non-zero value indicates the button was pressed, so you can evaluate it as a boolean.

If the instance is configured in one-shot mode, it will only return B3_PRESS once per debounced button press.

If the instance is configured in repeat mode, it will return B3_REPEAT_SLOW or B3_REPEAT_FAST to allow the code to differentiate between the first press and repeat presses (if desired).

Returns
0 - Not pressed
B3_PRESS - Was just pressed
B3_REPEAT_SLOW - A virtual "press" on slow repeat
B3_REPEAT_FAST - A virtual "press" on fast repeat

◆ held()

bool Bounce3::held ( void  )
Returns
true if the button is currently held down.

◆ heldFor() [1/2]

uint32_t Bounce3::heldFor ( uint32_t  millis)
Parameters
millisAtomic timestamp
Returns
How long the button has been held down in ms
0, if the button is not currently presesd

◆ heldFor() [2/2]

uint32_t Bounce3::heldFor ( void  )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ released()

uint32_t Bounce3::released ( void  )
Returns
The number of milliseconds the button was held down
or 0 if the button was not just released.

◆ changed()

bool Bounce3::changed ( void  )
Returns
true if the button was just pressed or released

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