Advertisement
silver2row

Trying w/ sysfs_pwm

May 24th, 2023
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # Use for PWM on /dev/bone/pwm/
  4.  
  5. from pathlib import Path
  6. from PWMSone import Pwm  # see https://pastebin.com/R70P1wAn
  7. from time import sleep
  8.  
  9. pwm1b = Pwm('/dev/bone/pwm/1/b', frequency=50, value=0)
  10. pwm1a = Pwm('/dev/bone/pwm/1/a', frequency=50, value=0)
  11.  
  12. GPIO  = Path('/sys/class/gpio/gpio60/direction')
  13. GPIO.write_text('out')
  14. GPIO  = Path('/sys/class/gpio/gpio60/value')
  15. GPIO.write_text('0')
  16.  
  17. #GPIO1 = Path('/sys/class/gpio/gpio44/direction')
  18. #GPIO1.write_text('out')
  19. #GPIO1 = Path('/sys/class/gpio/gpio44/value')
  20. #GPIO1.write_text('0')
  21.  
  22. # https://pastebin.com/R70P1wAn
  23.  
  24. # initialize and enable pwm, automatically disable when scope is left
  25. #with Pwm('/dev/bone/pwm/1/b', frequency=20000, value=0) as pwm:
  26. #    while True:
  27. #        pwm.value = float(input("Enter PWM value (between 0.0 and 1.0): "))
  28.  
  29. try:
  30.     while True:
  31.         port = float(input("Please type a 0 or a 1 : "))
  32.         if port == 0:
  33.             GPIO.write_text('1')
  34.             sleep(1)
  35.             frequency=150
  36.             pwm1b.value=1.0
  37.             sleep(1)
  38.         elif port == 1:
  39.             GPIO.write_text('1')
  40.             sleep(1)
  41.             frequency=70
  42.             pwm1b.value=0.1
  43.             sleep(1)
  44.  
  45. except KeyboardInterrupt:
  46.     GPIO.write_text("0")
  47. #    GPIO1.write_text("0")
  48.     pwm1b.enabled = False
  49.     print("Kosher Salt!")
  50.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement