import RPi.GPIO as GPIO import time led = 23 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(led,GPIO.OUT) p1 = GPIO.PWM(led, 50) # GPIO PWM with 50Hz p1.start(0) # Initialization print "CTRL+C = STOP program" try: while True: for n in range(0,50,10): p1.ChangeDutyCycle(n) time.sleep(0.5) else: GPIO.output(led,GPIO.LOW) except KeyboardInterrupt: GPIO.cleanup() # must be executed before program stop