Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/env python
  2. # PWM teste fade
  3.  
  4. import RPi.GPIO as GPIO
  5. import time
  6.  
  7. GPIO.setmode(GPIO.BCM)
  8. GPIO.setup(18, GPIO.OUT)
  9.  
  10. p = GPIO.PWM(18, 50)  # channel=18 frequency=50Hz
  11. p.start(0)
  12. try:
  13.     while 1:
  14.         for dc in range(0, 101, 5):
  15.             p.ChangeDutyCycle(dc)
  16.             time.sleep(0.1)
  17.         for dc in range(100, -1, -5):
  18.             p.ChangeDutyCycle(dc)
  19.             time.sleep(0.1)
  20. except KeyboardInterrupt:
  21.     p.stop()
  22.     GPIO.cleanup()