You change pin from output to input temporarily to detect button state,
if butt pressed you bounce it in then then out, flip a flag, then go back to
output, and set its state based on flag.
Note if you hold button down the led turns on, even if flag indicates its supposed
to be off, until its released and bounced out (off).
Regards, Dana.