-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalign.py
73 lines (53 loc) · 1.84 KB
/
align.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
#####################################SETUP#######################################
# Standard setup starts
import RPi.GPIO as GPIO, time, os
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
# Standard setup ends
def RCtime (RCpin): ## Setup LDR detection
reading = 0
GPIO.setup(RCpin, GPIO.OUT)
GPIO.output(RCpin, GPIO.LOW)
time.sleep(0.05)
GPIO.setup(RCpin, GPIO.IN)
# This takes about 1 millisecond per loop cycle
while (GPIO.input(RCpin) == GPIO.LOW):
reading += 1
return reading
# define function flashing LED - flash rate defined in the call
def flashled( str ):
GPIO.setup(22, GPIO.OUT) ##Setup LED
GPIO.output(22, True)
time.sleep(str)
GPIO.output(22, False)
time.sleep(str)
# define function playing sound - file defined in call
def playsound( str ):
bashCommand = str
import subprocess
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
# define function
def laseron():
GPIO.setup(17, GPIO.OUT) ##Setup Laser
GPIO.output(17, True) ## Laser on
# define function
def laseroff():
GPIO.setup(17, GPIO.OUT) ##Setup Laser
GPIO.output(17, False) ## Laser on
def checker():
## this quickly pulses the laser and checks if a signal is recieved if not recieved triggers setup.
laseron(); # turn laser on pin #17
# delare variable
if (RCtime(18) < 1001): ## signal detected STANDBY MODE
laseroff() # turn laser off
print "aligned"
print (RCtime(18)
laseroff();
elif (RCtime(18) >1000):## no signal ALIGN LASER
print "not aligned"
print (RCtime(18)
#AlignLaser() ## calls align laser function (at the top)
laseroff();
laseroff();
checker()