Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Debouncer< T > Class Template Reference
Dr Marty's switch debounce algorihm for shift registers and GPIO pins. More...
#include <Debouncer.hpp>
Detailed Description
template<typename T>
class Debouncer< T >
Dr Marty's switch debounce algorihm for shift registers and GPIO pins.
In order to use this class, simply feed the constructor the address of the memory you want to store the debounced data too. This allows the debounced General Purpose Inputs (GPI) and shift register inputs to to be packed into a single array of bytes so they can be quickly polled.
// 100Hz polling example with one 74HC165 shift register and GPI Port. #include "mbed.h" #include "debouncer.hpp" SPI Spi1 (D11, D12, D13); DigitalOut Spi1CS (D10); Ticker PollInputsTicker; PortIn GPIPort (PortA); char InputStates[5]; Debouncer<int> GPIPortDebouncer ((int*)&InputStates[0]); Debouncer<char> ShiftRegisterDebouncer (&InputStates[4]); void PollInputsHandler () { Spi1CS = 1; char shift = ShiftRegisterDebouncer.Debounce (Spi1.write (0)); int portA = GPIPortDebouncer.Debounce (GPIPort); Spi1CS = 0; } int main() { PollInputsTicker.attach (&PollInputsHandler, 1.0f / 100.0f); Spi1.format (8,3); Spi1.frequency (115200); while (true) ; }
Definition at line 49 of file Debouncer.hpp.
Generated on Wed Aug 10 2022 13:01:14 by
