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 |
sub function Button(dim byref port as byte, dim pin, time, active_state as byte) as byte |
---|---|
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 : program Button_Test dim oldstate as bit main: DDB0_bit = 0 ' set Button pin as input DDRC = 0xFF ' configure PORTC as output PORTC = 0xAA ' initial PORTC value oldstate = 0 ' oldstate initial value while TRUE if (Button(PINB, 0, 1, 1) <> 0) then ' detect logical one oldstate = 1 ' update flag end if if (oldstate and Button(PINB, 0, 1, 0)) then ' detect one-to-zero transition PORTC = not PORTC ' invert PORTC oldstate = 0 ' update flag end if wend ' endless loop end. |
What do you think about this topic ? Send us feedback!