Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ERROR:
- Traceback (most recent call last):
- File "/home/debian/Ball_Screw/./first_try.py", line 50, in <module>
- GPIO.value = 1
- File "/home/debian/Ball_Screw/./first_try.py", line 37, in value
- self._f.write((b'0',b'1')[value])
- PermissionError: [Errno 1] Operation not permitted
- Source:
- #!/usr/bin/python3
- # I think this is from @zmatt, i.e. circa '22.
- # I, Seth, have changed some of it...
- # Now, it is broken. I am slowly fixing it!
- import os
- from time import sleep
- from pathlib import Path
- class Gpio:
- def __init__(self, gpio, rw=None):
- if type(gpio) is int:
- # gpio number
- self.path = 'gpio31' + str(gpio)
- self.path = 'gpio48' + str(gpio1)
- self.path = 'gpio51' + str(gpio2)
- else:
- # gpio name or path
- self.path = os.path.join('/sys/class/gpio', gpio)
- if rw is not None and type(rw) is not bool:
- raise TypeError()
- if rw:
- self._f = open(self.path + '/value', 'r+b', buffering=0)
- else:
- self._f = open(self.path + '/value', 'rb', buffering=0)
- self.rw = rw
- @property
- def value(self):
- return (b'0', b'1').index(os.pread(self._f.fileno(), 1, 0))
- @value.setter
- def value(self, value):
- if self.rw is None:
- self._f = open(self.path + '/value', 'r+b', buffering=0)
- self.rw = True
- self._f.write((b'0',b'1')[value])
- ## example:
- try:
- while True:
- # my_input = Gpio('P9_14')
- GPIO = Gpio('gpio31')
- GPIO1 = Gpio('gpio48')
- GPIO2 = Gpio('gpio51')
- #print( my_input.value )
- GPIO.value = 1
- GPIO1.value = 1
- GPIO2.value = 1
- sleep(1)
- GPIO.value = 1
- GPIO1.value = 0
- GPIO2.value = 1
- sleep(1)
- print("First Value: \n".format(GPIO.value), "Second Value: \n".format(GPIO1.value),
- ("Third Value: \n".format.GPIO2.value))
- except KeyboardInterrupt:
- print("Trying to Care for the Behemoth!", Interruptions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement