State machine button scan implementation