The biggest error is during the delay function. That blocks anything else from happening look at the code in:-