You're missing {} for the if. Only the delay(500) is conditionally executed if the pin is LOW hence slowing down the process. The three lines after that are always executed regardless if the condition is true or false.
You're missing {} for the if. Only the delay(500) is conditionally executed if the pin is LOW hence slowing down the process. The three lines after that are always executed regardless if the condition is true or false.