Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from time import sleep
- import os
- from pathlib import Path
- Direction_One = Path('/sys/class/gpio/gpio44/direction')
- Direction_Two = Path('/sys/class/gpio/gpio45/direction')
- #Disable_Three = Path('/dev/gpio/P9_11/direction')
- class Gpio:
- def __init__( self, gpio, rw=None ):
- # if type(gpio) is int:
- # gpio number
- # self.path = '/sys/class/gpio/gpio' + str(gpio)
- # else:
- # gpio name or path
- self.path = os.path.join( '/sys/class/gpio/' + str(gpio))
- # if rw is not None and type(rw) is not bool:
- # raise TypeError()
- # if rw:
- # self._f = open(self.path + 'direction', 'r+b', buffering=0)
- # else:
- # self._f = open(self.path + 'direction', 'rb', buffering=0)
- 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'1',b'0').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'1',b'0')[ value ] )
- '''
- @property
- def direction( self ):
- return (b'1', b'0').index( os.pread( self._f.fileno(), 1, 0 ) )
- @direction.setter
- def direction( self, direction ):
- if self.rw is None:
- self._f = open( self.path + 'direction', 'r+b', buffering=0 )
- self.rw = True
- self._f.write( (b'1', b'0')[ direction ] )
- '''
- ## example:
- Direction_One.write_text('out')
- Direction_Two.write_text('out')
- #Disable_Three.write_text('in')
- try:
- arc = float(input("Please enter in a float! "))
- steps_to_move = 500
- step_count = 0
- direction = 0
- step_delay = 0.1
- while True:
- DIR = Gpio('gpio44/')
- STEP = Gpio('gpio45/')
- print( DIR.value )
- print( STEP.value )
- if arc >= 1:
- DIR.value = 0
- STEP.value = 1
- sleep(4)
- if DIR.value == direction:
- STEP.value = 1
- sleep(step_delay)
- step_count = step_count + 1
- if step_count == steps_to_move:
- step_count = 0
- if direction >= True:
- direction = 0
- else:
- direction = 1
- except KeyboardInterrupt:
- STEP.value = 0
- pass
- print("Over and done! ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement