How to execute functions simultaneously in this case?

An ESP32 comes with freeROTOS a good state machine and multitasker and multiprocessor OS, as an FYI.