Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding=utf8
  3.  
  4. import os.path
  5.  
  6. def gpio_create(fnum):
  7.         fpath = "/sys/class/gpio/gpio" + str(fnum)
  8.         if not os.path.isfile(fpath):
  9.                 file_ = open("/sys/class/gpio/export", "w")
  10.                 file_.write(str(fnum))
  11.                 file_.close()
  12.  
  13. def gpio_set_direction(fnum, direction):
  14.         fpath = "/sys/class/gpio/gpio" + str(fnum)
  15.         if os.path.isfile(fpath):
  16.                 dpath = fpath + "/direction"
  17.                 file_ = open(dpath, "w")
  18.                 file_.write(str(direction))
  19.                 file_.close()
  20.  
  21. def gpio_set_state(fnum, value):
  22.         fpath = "/sys/class/gpio/gpio" + str(fnum)
  23.         if os.path.isfile(fpath):
  24.                 vpath = fpath + "/value"
  25.                 file_ = open(vpath, "w")
  26.                 file_.write(str(value))
  27.                 file_.close()
  28.  
  29. gpio_create(232)
  30. gpio_set_direction(232, 'out')
  31. gpio_set_state(232, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement