Added functions for button detection and debouncing.