Skip to content

Commit fa19bf5

Browse files
committed
Adding code for Party Parrot Zoetrope
Adding CircuitPython code for the Party Parrot Zoetrope Learn Guide. Uses the Crickit.
1 parent edc9d22 commit fa19bf5

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Party_Parrot_Zoetrope/code.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from adafruit_crickit import crickit
2+
3+
# crickit setup
4+
ss = crickit.seesaw
5+
# pin for photo interrupter
6+
photo = crickit.SIGNAL1
7+
ss.pin_mode(photo, ss.INPUT_PULLUP)
8+
9+
# dc motor setup
10+
motor = crickit.dc_motor_1
11+
12+
# party parrot colors for the NeoPixel
13+
parrot_0 = (255, 75, 0)
14+
parrot_1 = (255, 200, 0)
15+
parrot_2 = (90, 255, 90)
16+
parrot_3 = (0, 255, 255)
17+
parrot_4 = (0, 160, 255)
18+
parrot_5 = (90, 0, 255)
19+
parrot_6 = (175, 0, 255)
20+
parrot_7 = (255, 0, 200)
21+
parrot_8 = (255, 0, 125)
22+
parrot_9 = (255, 0, 0)
23+
24+
colors = (parrot_0, parrot_1, parrot_2, parrot_3, parrot_4, parrot_5,
25+
parrot_6, parrot_7, parrot_8, parrot_9)
26+
27+
# setup using crickit neopixel library
28+
crickit.init_neopixel(1)
29+
crickit.neopixel.fill((parrot_0))
30+
31+
# counter for party parrot colors
32+
z = 0
33+
# speed for the dc motor
34+
speed = 0.3
35+
36+
while True:
37+
# begin the dc motor
38+
# will run throughout the loop
39+
motor.throttle = speed
40+
# read the input from the photo interrupter
41+
data = ss.digital_read(photo)
42+
43+
# if the photo interrupter detects a break:
44+
if data is True:
45+
# debug print
46+
print(z)
47+
# change the neopixel's color to the z index of the colors array
48+
crickit.neopixel.fill((colors[z]))
49+
# increase z by 1
50+
z += 1
51+
# if z reaches the end of the colors array...
52+
if z > 9:
53+
# index is reset
54+
z = 0

0 commit comments

Comments
 (0)