-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathardFunc.py
68 lines (47 loc) · 1.3 KB
/
ardFunc.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# move a servo from a Tk slider - scruss 2012-10-28
import pyfirmata
import time
import sounddevice as sd
import soundfile as sf
# don't forget to change the serial port to suit
board = pyfirmata.Arduino('COM5')
# start an iterator thread so
# serial buffer doesn't overflow
filename = 'audios/lock.wav'
# Extract data and sampling rate from file
data, fs = sf.read(filename, dtype='float32')
# set up pin D9 as Servo Output
pin9 = board.get_pin('d:9:s')
pin10 = board.get_pin('d:10:s')
pin11 = board.get_pin("d:11:s")
pin13 = board.get_pin('d:13:o')
pin9.write(90)
pin10.write(90)
pin11.write(180 - 44)
def fire(sound=False):
print("firing")
pin11.write(180 - 66)
time.sleep(.2)
pin11.write(180 - 44)
if sound:
sd.play(data, fs, device=6)
status = sd.wait() # Wait until file is done playing
time.sleep(.2)
# set up GUI
def laserOn():
pin13.write(1)
def laserOff():
pin13.write(0)
# draw a nice big slider for servo position
def laserFunc(cx, cy):
serx = int(cx)
sery = int(cy)
pin9.write(serx)
pin10.write(sery)
y_max = 48
y_min = 85
x_max = 0
x_min = 0
#84 62