Advertisement
silver2row

second_rendition

Mar 19th, 2023
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 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 NewMotor_TB6600 import Pwm  # see https://pastebin.com/R70P1wAn
  7. from time import sleep
  8. import gpiod
  9.  
  10. CHIP = 'gpiochip1'
  11. LINE_OFFSET = [28]
  12.  
  13. chip = gpiod.Chip(CHIP)
  14.  
  15. lines = chip.get_lines(LINE_OFFSET)
  16. lines.request(consumer=' ', type=gpiod.LINE_REQ_DIR_OUT)
  17.  
  18. lines.set_values([0])
  19.  
  20. pwm1aP = Path('/dev/bone/pwm/1/a/period')
  21. pwm1aD_C = Path('/dev/bone/pwm/1/a/duty_cycle')
  22. pwm1aE = Path('/dev/bone/pwm/1/a/enable')
  23.  
  24. pwm1bP = Path('/dev/bone/pwm/1/b/period')
  25. pwm1bD_C = Path('/dev/bone/pwm/1/b/duty_cycle')
  26. pwm1bE = Path('/dev/bone/pwm/1/b/enable')
  27.  
  28. period = 10000
  29. duty_cycle = 5000
  30.  
  31. try:
  32.     while True:
  33.         port = int(input("Please type 0 or 1 : "))
  34.         if port == 0:
  35.             lines.set_values([1])
  36.             pwm1bP = 10000
  37.             pwm1bD_C = 8000
  38.             pwm1bE = 1
  39.             sleep(0.5)
  40.         elif port == 1:
  41.             lines.set_values([1])
  42.             pwm1aP = 10000
  43.             pwm1aD_C = 5000
  44.             pwm1aE = 1
  45.             sleep(3)
  46. except KeyboardInterrupt:
  47.     pwm1bE = 0
  48.     pwm1aE = 0
  49.     print("Kosher Salt!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement