Feb-17-2021, 10:34 AM
This is a great example of why the comments should never duplicate the code. 100 steps instead of 200, sleep 10 ms instead of 30. Comments should be seldom and describe purpose, not implementation. If the implementation is unclear, change the code to make the implementation clear.
I think your problem is caused by not stopping PWM. Since PWM is toggling power on/off at some frequency/duty cycle I would expect this to override setting the GPIO output. What happens if you run this?
I think your problem is caused by not stopping PWM. Since PWM is toggling power on/off at some frequency/duty cycle I would expect this to override setting the GPIO output. What happens if you run this?
import RPi.GPIO as GPIO from time import sleep GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.OUT) # Using PWM ramp power from 0 to 100% pwm=GPIO.PWM(11,100) pwm.start(0) for x in range(100): pwm.ChangeDutyCycle(x) sleep(0.01) # Stop PWM and toggle LED on/off at 1 second intervals pwm.stop() for _ in range(10) GPIO.output(11, GPIO.HIGH) sleep(1) GPIO.output(11, GPIO.LOW) sleep(1)