Of course, the project didn’t allow us to use an RTOS.
That tends to just make the project eventually implement an approximation of one... as what appears to have happened here.
How I'd solve the given problem is by using the PWM peripheral (or timer interrupts if no PWM peripheral exists) and pin change interrupts, with the CPU halted nearly 100% of the time. I suspect that approach is even simpler than what's shown here.
replies(1):