Advertisement
silver2row

Trying what I think is OS and Python3

Mar 23rd, 2023
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. ERROR:
  2.  
  3. Traceback (most recent call last):
  4.   File "/home/debian/Ball_Screw/./first_try.py", line 50, in <module>
  5.     GPIO.value  = 1
  6.   File "/home/debian/Ball_Screw/./first_try.py", line 37, in value
  7.     self._f.write((b'0',b'1')[value])
  8. PermissionError: [Errno 1] Operation not permitted
  9.  
  10. Source:
  11.  
  12. #!/usr/bin/python3
  13.  
  14. # I think this is from @zmatt, i.e. circa '22.
  15. # I, Seth, have changed some of it...
  16. # Now, it is broken. I am slowly fixing it!
  17.  
  18. import os
  19. from time import sleep
  20. from pathlib import Path
  21.  
  22. class Gpio:
  23.     def __init__(self, gpio, rw=None):
  24.         if type(gpio) is int:
  25.             # gpio number
  26.             self.path = 'gpio31' + str(gpio)
  27.             self.path = 'gpio48' + str(gpio1)
  28.             self.path = 'gpio51' + str(gpio2)
  29.         else:
  30.             # gpio name or path
  31.             self.path = os.path.join('/sys/class/gpio', gpio)
  32.  
  33.         if rw is not None and type(rw) is not bool:
  34.             raise TypeError()
  35.  
  36.         if rw:
  37.             self._f = open(self.path + '/value', 'r+b', buffering=0)
  38.         else:
  39.             self._f = open(self.path + '/value', 'rb', buffering=0)
  40.         self.rw = rw
  41.  
  42.     @property
  43.     def value(self):
  44.         return (b'0', b'1').index(os.pread(self._f.fileno(), 1, 0))
  45.  
  46.     @value.setter
  47.     def value(self, value):
  48.         if self.rw is None:
  49.             self._f = open(self.path + '/value', 'r+b', buffering=0)
  50.             self.rw = True
  51.  
  52.         self._f.write((b'0',b'1')[value])
  53.  
  54. ## example:
  55.  
  56. try:
  57.     while True:
  58.         # my_input = Gpio('P9_14')
  59.         GPIO  = Gpio('gpio31')
  60.         GPIO1 = Gpio('gpio48')
  61.         GPIO2 = Gpio('gpio51')
  62.  
  63. #print( my_input.value )
  64.  
  65.         GPIO.value  = 1
  66.         GPIO1.value = 1
  67.         GPIO2.value = 1
  68.         sleep(1)
  69.  
  70.         GPIO.value  = 1
  71.         GPIO1.value = 0
  72.         GPIO2.value = 1
  73.         sleep(1)
  74.  
  75.         print("First Value: \n".format(GPIO.value), "Second Value: \n".format(GPIO1.value),
  76.              ("Third Value: \n".format.GPIO2.value))
  77. except KeyboardInterrupt:
  78.     print("Trying to Care for the Behemoth!", Interruptions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement