Button Library
The Button Library provides routines for detecting button presses and debouncing (eliminating the influence of contact flickering upon pressing a button).
Library Routines
Button
Prototype |
unsigned short Button(unsigned short *port, unsigned short pin, unsigned short time, unsigned short active_state); |
---|---|
Returns |
|
Description |
Function eliminates the influence of contact flickering upon pressing a button (debouncing). Parameter |
Requires |
Button pin must be configured as input. |
Example |
On every PB0 one-to-zero transition PORTC is inverted : bit oldstate; // Old state flag void main() { DDB0_bit = 0; // Set PB0 pin as input DDRC = 0xFF; // Configure PORTC as output PORTC = 0xAA; // Initial PORTC value oldstate = 0; do { if (Button(&PINB, 0, 1, 1)) { // Detect logical one oldstate = 1; // Update flag } if (oldstate && Button(&PINB, 0, 1, 0)) { // Detect one-to-zero transition PORTC = ~PORTC; // Invert PORTC oldstate = 0; // Update flag } } while(1); // Endless loop } |
What do you think about this topic ? Send us feedback!