Skip to content

Commit a79ac4e

Browse files
authored
Add files via upload
1 parent 887ba8a commit a79ac4e

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed
195 KB
Binary file not shown.
391 KB
Loading
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# SPDX-FileCopyrightText: 2018 John Edgar Park for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Animatronic Hand
6+
# Binary Counting on four fingers up to 15
7+
import time
8+
from digitalio import DigitalInOut, Direction, Pull
9+
import audioio
10+
import audiocore
11+
import board
12+
from adafruit_crickit import crickit
13+
14+
#################### CPX switch
15+
# use the CPX onboard switch to turn on/off (helps calibrate)
16+
switch = DigitalInOut(board.SLIDE_SWITCH)
17+
switch.direction = Direction.INPUT
18+
switch.pull = Pull.UP
19+
20+
#################### Audio setup
21+
print("Let's count in binary.")
22+
wavfiles = ("one.wav", "two.wav", "three.wav", "four.wav", "five.wav", "six.wav",
23+
"seven.wav", "eight.wav", "nine.wav", "ten.wav", "eleven.wav",
24+
"twelve.wav", "thirteen.wav", "fourteen.wav", "fifteen.wav")
25+
introfile = "intro.wav"
26+
27+
cpx_audio = audioio.AudioOut(board.A0)
28+
def play_file(wavfile):
29+
with open(wavfile, "rb") as f:
30+
wav = audiocore.WaveFile(f)
31+
cpx_audio.play(wav)
32+
while cpx_audio.playing:
33+
pass
34+
35+
#################### 4 Servos!
36+
servos = (crickit.servo_1, crickit.servo_2, crickit.servo_3, crickit.servo_4)
37+
for servo in servos:
38+
servo.angle = 180 # starting angle, open hand
39+
40+
# Which servos to actuate for each number
41+
counting = (
42+
[3],
43+
[2],
44+
[3, 2],
45+
[1],
46+
[1, 3],
47+
[1, 2],
48+
[3, 2, 1],
49+
[0],
50+
[0, 3],
51+
[0, 2],
52+
[0, 3, 2],
53+
[0, 1],
54+
[0, 3, 1],
55+
[0, 2, 1],
56+
[0, 3, 2, 1]
57+
)
58+
59+
play_file(introfile)
60+
61+
while True:
62+
if not switch.value:
63+
continue
64+
65+
# the CPX switch is on, so do things
66+
for servo in servos: # close the fist
67+
servo.angle = 0 # close the fingers
68+
print("Servo %d angle = 0" % (servos.index(servo)+1) )
69+
time.sleep(.2)
70+
71+
time.sleep(1) # pause a moment
72+
73+
for i in range(len(counting)):
74+
# close all the counting fingers between numbers
75+
for servo in servos:
76+
servo.angle = 0 # close
77+
print("\t\tServo #%d angle 0" % (servos.index(servo)+1))
78+
time.sleep(0.3)
79+
80+
print("Number #%d \tfingers: %s" % (i+1, counting[i]))
81+
82+
# open just the indicated fingers when counting
83+
for finger in counting[i]:
84+
servos[finger].angle = 180 # open
85+
print("\t\tServo #%d angle 180" % (finger+1))
86+
time.sleep(0.3)
87+
# say it!
88+
play_file(wavfiles[i])
89+
# hold for a bit of time
90+
time.sleep(0.3)
91+
print("...")
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2018 John Edgar Park for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Animatronic Hand
6+
# CPX with CRICKIT and four servos
7+
# touch four cap pads to close the fingers
8+
9+
import board
10+
from digitalio import DigitalInOut, Direction, Pull
11+
from adafruit_crickit import crickit
12+
13+
#################### CPX switch
14+
# use the CPX onboard switch to turn on/off (helps calibrate)
15+
switch = DigitalInOut(board.SLIDE_SWITCH)
16+
switch.direction = Direction.INPUT
17+
switch.pull = Pull.UP
18+
19+
#################### 4 Servos!
20+
servos = (crickit.servo_1, crickit.servo_2, crickit.servo_3, crickit.servo_4)
21+
for servo in servos:
22+
servo.angle = 180 # starting angle, open hand
23+
24+
#################### 4 Touch sensors!
25+
touches = (crickit.touch_1, crickit.touch_2, crickit.touch_3, crickit.touch_4)
26+
27+
cap_state = [False, False, False, False]
28+
cap_justtouched = [False, False, False, False]
29+
cap_justreleased = [False, False, False, False]
30+
31+
curl_finger = [False, False, False, False]
32+
finger_name = ['Index', 'Middle', 'Ring', 'Pinky']
33+
34+
while True:
35+
if not switch.value: # the CPX switch is off, so do nothing
36+
continue
37+
# Check the cap touch sensors to see if they're being touched
38+
for i in range(4):
39+
cap_justtouched[i] = False
40+
cap_justreleased[i] = False
41+
42+
if touches[i].value:
43+
#print("CT" + str(i + 1) + " touched!")
44+
if not cap_state[i]:
45+
cap_justtouched[i] = True
46+
print("%s finger bent." % finger_name[i])
47+
servos[i].angle = 0
48+
# store the fact that this pad is touched
49+
cap_state[i] = True
50+
51+
else:
52+
if cap_state[i]:
53+
cap_justreleased[i] = True
54+
print("%s finger straightened." % finger_name[i])
55+
servos[i].angle = 180
56+
# print("CT" + str(i + 1) + " released!")
57+
# store the fact that this pad is NOT touched
58+
cap_state[i] = False
59+
60+
if cap_justtouched[i]:
61+
curl_finger[i] = not curl_finger[i]

0 commit comments

Comments
 (0)