Assistance in diploma. Question programming the Arduino mega

            digitalRead(31);

Read the state of the pin, throwing away the ONLY thing the function does. Why?

It's good to see that you grasped the concept of state machines and blink without delay. I predict you'll go far.