-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoey.py
84 lines (68 loc) · 1.68 KB
/
shoey.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
#!/usr/bin/python
import time
from Sunfounder_PWM_Servo_Driver import PWM
pwm = PWM(0x40)
pwm.setPWMFreq(60)
# Min found around 150
# Max found around 700
servoMin = 150
servoMax = 700
servoMid = servoMin + (servoMax - servoMin) / 2
debug = False
mouthChannel = 0
headChannel = 4
def log(string):
if debug:
print string
return
def setServoValue(channel, value):
pwm.setPWM(channel, 0, value)
log("Setting channel " + str(channel) + " to " + str(value))
return
def openMouthPercent(percent):
openValue = servoMin + 120
closedValue = servoMin
targetValue = closedValue + int((openValue - closedValue) * percent)
setServoValue(mouthChannel, targetValue)
def setMouthOpen(o = True):
if o:
log("Opening mouth")
openValue = servoMin + 120
setServoValue(mouthChannel, openValue)
else:
log("Closing mouth")
closedValue = servoMin
setServoValue(mouthChannel, closedValue)
return
W_LEFT = 0
W_CENTER = 1
W_RIGHT = 2
def wiggleInDirection(direction = W_CENTER):
log("Wiggling " + str(direction))
if direction == W_LEFT:
setServoValue(headChannel, servoMid - 70)
elif direction == W_CENTER:
setServoValue(headChannel, servoMid)
elif direction == W_RIGHT:
setServoValue(headChannel, servoMid + 70)
return
def laugh(count = 3):
for x in range(0, count):
setMouthOpen(True)
time.sleep(0.25)
setMouthOpen(False)
time.sleep(0.25)
wiggleInDirection(W_LEFT)
time.sleep(0.15)
wiggleInDirection(W_RIGHT)
time.sleep(0.15)
wiggleInDirection(W_LEFT)
time.sleep(0.15)
wiggleInDirection(W_CENTER)
return
print "For shoeth!"
wiggleInDirection(W_CENTER)
# while (True):
# laugh()
# time.sleep(3)
# print "Looping!"