树莓派呼吸灯

我是连接了2号io口,需要修改成你的io口

import time
import RPi.GPIO as GPIO 

GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.OUT)

p = GPIO.PWM(2, 150)
p.start(0) 
try:
    while 1:
        for dc in range(0, 101, 5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
        for dc in range(100, -1, -5):
            p.ChangeDutyCycle(dc)
            time.sleep(0.1)
except KeyboardInterrupt:
    pass
p.stop()
GPIO.cleanup() 

你可能感兴趣的:(树莓派呼吸灯)