silver2row

PWM_DRIVER usage and Testing on Fading

Apr 7th, 2026
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. from time import sleep
  4. import signal
  5. import sys
  6.  
  7. from pwm_driver import Pwm
  8.  
  9. LED = Pwm(path="/sys/class/pwm/pwmchip0/pwm0/", enabled=False, period=100000, duty_cycle=85000)
  10.  
  11. Duty = 0
  12. low  = 0.8 # Smallest angle (in ms)
  13. hi   = 2.4 # Largest angle (in ms)
  14. pos  = 1.5 # Current position, about middle ms)
  15. step = 0.4 # Step size to next position
  16.  
  17. try:
  18.     LED.enabled=True
  19.     while True:
  20.         pos += step    # Take a step
  21.         if(pos > hi or pos < low):
  22.             step *= -1
  23.         Duty = LED.duty_cycle
  24.         Duty = str(pos)
  25.         print('pos = ' + str(pos) + ' duty_cycle = ' + Duty)
  26.         (LED.duty_cycle)
  27.         sleep(0.2)
  28. except KeyboardInterrupt:
  29.     LED.enabled=False
  30.     pass
  31.  
  32. # Trying to fade a LED
  33. # This is from your (@zmatt) PWM driver written a while back and some code from docs.beagleboard.org
Advertisement
Add Comment
Please, Sign In to add comment