I am trying to execute the code where the LED will be blinking until the button is pressed. Once the button is pressed, the LED should be 'On' without blinking. The issue is that the LED keeps blinking even when the button is pressed. Here is my code:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
GPIO.output(17,True)
time.sleep(1)
GPIO.output(17, False)
time.sleep(1)
button_state=GPIO.input(2)
if button_state==True:
GPIO.output(17, True)