Need help at coding

Your code has a lot of for-loops and function-calls delay()

For-loops and while-loops are blocking
and delay() is blocking.

the function delay() should have better the name

freeze_microcontroller_COMPLETELY_stop_ALL_code_execution_until_freezing_time_is_over()

This means your whole code has to be NON-blocking
It will take you some time and some thinking it over to understand it.
Here is a small tutorial that shows the principle how to write non-blocking code