-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightScript.py
More file actions
53 lines (44 loc) · 1.21 KB
/
lightScript.py
File metadata and controls
53 lines (44 loc) · 1.21 KB
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
import RPi.GPIO as GPIO
import string
import socket
import time
import sys
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_addrs = ('192.168.1.231', 420)
print >>sys.stderr, 'starting up on %s port %s' % server_addrs
sock.bind(server_addrs)
sock.listen(1)
pin = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
p = GPIO.PWM(pin, 50)
p.start(0)
off = 12.5
on = 5
def SetAngle(angle):
duty = angle/18+2
GPIO.output(pin, True)
p.ChangeDutyCycle(duty)
time.sleep(1)
GPIO.output(pin, False)
p.ChangeDutyCycle(0)
print (angle)
while True:
print >>sys.stderr, 'waiting for connection'
connection, client_addrs = sock.accept()
try:
print >>sys.stderr, 'connection from', client_addrs
while True:
data = connection.recv(16)
print >>sys.stderr, 'recieved "%s"' % data
if data:
print >>sys.stderr, 'sending confirmation to the client'
SetAngle(int(data))
connection.sendall(data)
else:
print >>sys.stderr, 'no more data from', client_addrs
break
finally:
connection.close()
p.stop()
GPIO.cleanup()