Sorry I am a beginner to both Raspberry Pi and python. I am write a simple python program to use the pulse width modulator, Here is the code.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(12,GPIO.OUT)
pwm=GPIO.PWM(12,50)
pwm.start(0)
while True:
for i in range(50):
pwm.ChangeDutyCycle(i)
time.sleep(0.05)
for i in range(50,0,-1):
pwm.ChangeDutyCycle(i)
time.sleep(0.05)
I connected the led between 12 and ground with the suitable resistor. But when I execute, I don't get any error but it wont work.