Advertisement
silver2row

using SYSFS pwm stuff

Mar 19th, 2023
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1.  
  2. #!/usr/bin/python3
  3.  
  4. # Use for PWM on /dev/bone/pwm/
  5.  
  6. #from pathlib import Path
  7. from NewMotor_TB6600 import Pwm  # see https://pastebin.com/R70P1wAn
  8. from time import sleep
  9. import gpiod
  10. # import os
  11.  
  12. CHIP = 'gpiochip1'
  13. LINE_OFFSET = [28]
  14.  
  15. chip = gpiod.Chip(CHIP)
  16.  
  17. lines = chip.get_lines(LINE_OFFSET)
  18. lines.request(consumer=' ', type=gpiod.LINE_REQ_DIR_OUT)
  19.  
  20. lines.set_values([0])
  21.  
  22. pwm1b = Pwm('/dev/bone/pwm/1/b/')
  23. pwm1a = Pwm('/dev/bone/pwm/1/a/')
  24.  
  25. try:
  26.     while True:
  27.         port = int(input("Please type 0 or 1 : "))
  28.         if port == 0:
  29.             lines.set_values([1])
  30.             pwm1a.frequency = 2000
  31. #            pwm1a.enabled = True
  32.             pwm1a.value = 0.5
  33.             sleep(4)
  34.         elif port == 1:
  35.             lines.set_values([1])
  36.             pwm1b.frequency = 2000
  37. #            pwm1b.enabled = True
  38.             pwm1b.value = 0.5
  39.             sleep(4)
  40.  
  41. except KeyboardInterrupt:
  42.     pwm1b.enabled = False
  43.     pwm1a.enabled = False
  44.     print("Kosher Salt!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement