Is this all your program needs to do?
These two tutorials should help:
StateChangeDetection BlinkWithoutDelay