Staying in a subroutine

'Assuming' you're using an UNO, compare the pins you're using vs. the pins 0-3 on this schematic -

It's not a good idea to use the Tx/Rx pins for other than serial comms.

Can you confirm you're using an UNO?