import RPi.GPIO as gpioimport timeleds = [17,27,22]# led_pwm = list([])gpio.setmode(gpio.BCM)gpio.setup(leds, gpio.OUT)led_pwm = [gpio.PWM(led, 60)for led in leds][led.start(0)for led in led_pwm]try:whileTrue:for i inrange(0, 80, 5): [led.ChangeDutyCycle(i)for led in led_pwm] time.sleep(0.1)for i inrange(80, 0, -5): [led.ChangeDutyCycle(i)for led in led_pwm] time.sleep(0.1)exceptKeyboardInterrupt:pass[l.stop()for l in led_pwm]gpio.cleanup()
from gpiozero import LEDBoardfrom signal import pauseimport timepwmled =LEDBoard(17, 27, 22, pwm=True)v =0.1whileTrue:for led in pwmled: led.value = v time.sleep(1) v +=0.1if v >=1: v =0.1