Perhaps you should add a line to wait for the button to be released from the previous time it was pressed, before reading it again.