Guest User

Untitled

a guest
Sep 4th, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pathlib import Path
  2.  
  3. # initial configuration of a gpio, or changing it between input and output:
  4. Path('/dev/gpio/P2_35/direction').write_text('in')      # configure as input
  5. Path('/dev/gpio/P2_35/direction').write_text('low')     # configure as output, initially low
  6. Path('/dev/gpio/P2_35/direction').write_text('high')    # configure as output, initially high
  7.  
  8. # if configured as input, can read value with:
  9. value = int( Path('/dev/gpio/P2_35/value').read_text() )
  10. # value is 0 (for low) or 1 (for high)
  11.  
  12. # if configured as output, change value with:
  13. Path('/dev/gpio/P2_35/value').write_text('0')  # set low
  14. Path('/dev/gpio/P2_35/value').write_text('1')  # set high
Advertisement
Add Comment
Please, Sign In to add comment