Skip to content

Commit 4736451

Browse files
authored
Add files via upload
1 parent fcbbd65 commit 4736451

File tree

1 file changed

+68
-0
lines changed
  • Crickits/Mini_Chair_Swing_Ride

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Isaac Wellish
6+
# Code adapted from Anne Barela's Hello World of Robotics and
7+
# Make it Move with Crickit guides at learn.adafruit.com
8+
# Power must be plugged into right side of motor 1 on CRICKIT
9+
# to turn counter clock wise
10+
11+
import time
12+
import audioio
13+
import audiocore
14+
import board
15+
import neopixel
16+
from digitalio import DigitalInOut, Pull, Direction
17+
from adafruit_crickit import crickit
18+
19+
# Set audio out on speaker
20+
speaker = audioio.AudioOut(board.A0)
21+
22+
# Two onboard CPX buttons for input (low level saves memory)
23+
button_a = DigitalInOut(board.BUTTON_A)
24+
button_a.direction = Direction.INPUT
25+
button_a.pull = Pull.DOWN
26+
27+
button_b = DigitalInOut(board.BUTTON_B)
28+
button_b.direction = Direction.INPUT
29+
button_b.pull = Pull.DOWN
30+
31+
# Create one motor on seesaw motor port #1
32+
motor = crickit.dc_motor_1
33+
34+
# NeoPixels on the Circuit Playground Express Light Blue
35+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.7)
36+
# Fill them with our favorite color "#0099FF light blue" -> 0x0099FF
37+
# (see http://www.color-hex.com/ for more colors and find your fav!)
38+
39+
# set pixels to blue on start up
40+
pixels.fill(0x0099FF)
41+
42+
motorInc = 0
43+
44+
# Start playing the file (in the background)
45+
def play_file(wavfile):
46+
audio_file = open(wavfile, "rb")
47+
wav = audiocore.WaveFile(audio_file)
48+
speaker.play(wav,loop = True)
49+
50+
while True:
51+
if button_a.value:
52+
pixels.fill(0xFC4044)
53+
play_file("circus_chair.wav") # play WAV file
54+
motor.throttle = -0.20
55+
time.sleep(0.2)
56+
motor.throttle = -0.11 + motorInc # increase speed
57+
motorInc -= 0.01
58+
59+
if button_b.value:
60+
speaker.stop()
61+
pixels.fill(0x0099FF) # magenta
62+
i = motor.throttle
63+
while i < -0.05:
64+
i += 0.005
65+
motor.throttle = i # slow down!
66+
time.sleep(0.1)
67+
motor.throttle = 0 # stop
68+
motorInc = 0

0 commit comments

Comments
 (0)