SHARE
TWEET

Untitled

a guest Feb 17th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import RPi.GPIO as GPIO
  2. import time
  3. GPIO.setmode(GPIO.BCM)  # choose BCM or BOARD numbering schemes. I use BCM  
  4. GPIO.setup(26, GPIO.OUT)# set GPIO 26 as output for led  
  5. led= GPIO.PWM(26,100)   # create object led for PWM on port 25 at 100 Hertz  
  6. led.start(0)            # start led on 0 percent duty cycle (off)  
  7. pause_time = 0.02       # you can change this to slow down/speed up  
  8.  
  9. try:  
  10.     while True:  
  11.         for i in range(0,101):    # 101 because it stops when it finishes 100  
  12.             led.ChangeDutyCycle(i)  
  13.             sleep(pause_time)  
  14.         for i in range(100,-1,-1):      # from 100 to zero in steps of -1  
  15.             led.ChangeDutyCycle(i)  
  16.             sleep(pause_time)  
  17.  
  18. except KeyboardInterrupt:  
  19.     led.stop()            # stop the led PWM output  
  20.     GPIO.cleanup()        # clean up GPIO on CTRL+C exit
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top