سلام میتونی از دستور while استفاده کنی و البته دستور مناسب برای شمارش زمان millis:

https://www.arduino.cc/en/reference/millis