Yeah, we could also make a timer using millis() etc.
Not sure whether your code works more than one cycle?