Advertisement
silver2row

Replicate sysfs with bus

Jul 5th, 2020
2,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import time
  4.  
  5. with open("/sys/bus/i2c/drivers/pca9685-pwm/2-0070/pwm/pwmchip9/pwm-9:0/enable", "w+") as a:
  6.     a.read()
  7.     a.write == "0"
  8.     time.sleep(2)
  9.     a.write == "1"
  10.  
  11. with open("/sys/bus/i2c/drivers/pca9685-pwm/2-0070/pwm/pwmchip9/pwm-9:0/period", "w+") as b:
  12.     b.read()
  13.     b.write = "10000000"
  14.     # b.close()
  15.  
  16. with open("/sys/bus/i2c/drivers/pca9685-pwm/2-0070/pwm/pwmchip9/pwm-9:0/duty_cycle", "w+") as c:
  17.     c.read()
  18.     c.write = "1000000"
  19.     # c.close()
  20.  
  21. for i in range(0, 180, 5):
  22.     angle = int(input("0 to 180: "))
  23.     if angle < 45:
  24.         time.sleep(2)
  25.         a = "1"
  26.         c = "1500000"
  27.  
  28.     elif angle >= 45:
  29.         time.sleep(2)
  30.         a = "1"
  31.         c = "2000000"
  32.  
  33.     elif angle <= 180:
  34.         time.sleep(2)
  35.         a = "1"
  36.         b = "10000000"
  37.         c = "2000000"
  38.  
  39.     elif angle == 135:
  40.         time.sleep(2)
  41.         a = "1"
  42.         c = "1500000"
  43.  
  44.     else:
  45.         angle == 90
  46.         time.sleep(2)
  47.         a = "1"
  48.         c = "2000000"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement