Problem regarding the use of the function millis()

pert:
Your code doesn't make any sense.

This.

First, using a while() loop to wait until millis gives the right time defeats the whole purpose.

Secondly, the += will increase time_now by period every pass through the while loop test.

There is a specific way to use millis() correctly - the guide per linked describes it.