-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvulcan_trap.py
executable file
·112 lines (95 loc) · 2.25 KB
/
vulcan_trap.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import serial
import picamera
from time import sleep
from datetime import datetime
import pygame
import os
inputstr = ''
def RelayCtrl(relay, state):
inputstr = ""
ser.write(str(relay))
ser.write(str(int(state)))
ser.write("\n")
while inputstr != 'ACK\n':
inputstr = ser.readline()
if inputstr == 'ERR\n':
print "ERROR!"
return False
print inputstr
return True
def GetPin(in_pin):
inputstr = ""
ser.write("?")
ser.write(str(in_pin))
ser.write("\n")
while inputstr != '1\n':
inputstr = ser.readline()
if inputstr == '0\n':
return False
if inputstr == 'ERR\n':
print 'ERROR!'
return False
return True
def GetAPin(in_pin):
inputstr = ""
ser.write("?A")
ser.write(str(in_pin))
ser.write("\n")
if inputstr == 'ERR\n':
print 'ERROR!'
return False
return float(inputstr)
def Fire(time=5):
t = datetime.utcnow()
pygame.mixer.music.play()
RelayCtrl(1, True)
cam.capture("shooting" + str(t.date()) + str(t.time()) + ".jpg")
sleep(time-1.5)
RelayCtrl(1, False)
cam = picamera.PiCamera()
cam.brightness = 58
cam.resolution = (2592, 1944)
pygame.mixer.init()
pygame.mixer.music.load("dalek-exterminate.wav")
os.system('amixer set PCM 400')
#Open the serial link to the Arduino
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
print ser
#Verify that the Arduino is ready
c = 0
while inputstr != 'READY\n':
inputstr = ser.readline()
if c >= 5:
c = 0
ser.write("C\n") #Say "Hey, are you there?!?!"
else:
c += 1
print inputstr
#Ensure motion sensor has warmed up properly
sleep(10)
while GetPin(1):
sleep(1)
#Check that all relays are off
for r in range(1, 5):
print "Pulling relay #" + str(r) + " low..."
RelayCtrl(r, False)
print "All relays off, beginning main loop..."
#Just being OCD that the motion sensor is functioning properly
while GetPin(1):
sleep(1)
#Main Loop
run = True
i = 0
while run:
if GetPin(1) == True:
RelayCtrl(2,True)
Fire(2)
print 'F'
sleep(3)
RelayCtrl(2,False)
if i >= 5*60*100:
print '.'
i = 0
else:
i += 1
sleep(.01)