-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpio.py
executable file
·71 lines (59 loc) · 2.44 KB
/
gpio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
#/etc/sudoers add rule under sudo:
#pi ALL=(ALL) NOPASSWD: /usr/local/bin gpio
'''
Tool to turn on and off GPIO pin
@file
@author Anne Munoz<[email protected]>
@date February 25, 2016
@copyright LGPL v2.1
'''
#------------------------------------------------------------------------------|
# GNU LESSER GENERAL PUBLIC LICENSE |
# ------------------------------------ |
# This source file is free software; you can redistribute it and/or modify it |
# under the terms of the GNU Lesser General Public License as published by the |
# Free Software Foundation; either version 2.1 of the License, or (at your |
# option) any later version. This source is distributed in the hope that it |
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warrant |
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
# General Public License for more details. You should have received a copy of |
# the GNU Lesser General Public License along with this source; if not, |
# download it from http://www.gnu.org/licenses/lgpl-2.1.html |
#------------------------------------------------------------------------------|
import RPi.GPIO as GPIO
import time
import sys
GPIO.setmode(GPIO.BCM)
WRLEN = [17, 27, 22] #Pines de conexion de los reles de las WR-LEN
GPIO.setwarnings(False)
try:
GPIO.setup(WRLEN[0], GPIO.OUT)
GPIO.setup(WRLEN[1], GPIO.OUT)
GPIO.setup(WRLEN[2], GPIO.OUT)
except Exception as e:
print e
def apaga(len):
GPIO.output(len, GPIO.LOW)
#print 'Off',len
def enciende(len):
GPIO.output(len, GPIO.HIGH)
#print "On", len
if __name__ == "__main__":
if len(sys.argv) > 2:
if str(sys.argv[2]) == 'on':
try:
enciende(int(sys.argv[1]))
except Exception as e:
print e
elif str(sys.argv[2]) == 'off':
try:
apaga(int(sys.argv[1]))
except Exception as e:
print e
else:
print "usage: python gpi.py <number> <status>"
print
print "where:"
print "\t -number is 17 or 22 or 27"
print "\t -status on or off"