Raspberry PI PWM LED controlados
import RPi.GPIO as GPIO
from time import sleep
redLED = 18
blueLED = 12
greenLED = 19
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(redLED,GPIO.OUT)
GPIO.setup(blueLED,GPIO.OUT)
GPIO.setup(greenLED,GPIO.OUT)
red_pwm = GPIO.PWM(redLED,1000)
blue_pwm = GPIO.PWM(blueLED,1000)
green_pwm = GPIO.PWM(greenLED,1000)
red_pwm.start(0)
blue_pwm.start(0)
green_pwm.start(0)
print("AH Shit! Here we go again! Press CTRL+C to exit")
try:
while True:
for duty in range(0,101,1):
red_pwm.ChangeDutyCycle(duty)
sleep(0.01)
sleep(0.5)
for duty in range(100,-1,-1):
red_pwm.ChangeDutyCycle(duty)
sleep(0.01)
sleep(0.5)
for duty in range (0, 101, 1):
blue_pwm.ChangeDutyCycle(duty)
sleep(0.01)
sleep(0.5)
for duty in range (100, -1, -1):
blue_pwm.ChangeDutyCycle(duty)
sleep(0.01)
sleep(0.5)
for duty in range(0,101,1):
green_pwm.ChangeDutyCycle(duty)
sleep(0.01)
sleep(0.5)
for duty in range(100,-1,-1):
green_pwm.ChangeDutyCycle(duty)
sleep(0.01)
sleep(0.5)
except KeyboardInterrupt:
red_pwm.stop()
blue_pwm.stop()
green_pwm.stop()
GPIO.cleanup()
Hemanthnag Bollepalli