Skip to content

Commit 4c7517f

Browse files
authored
Merge pull request adafruit#2889 from adafruit/LEGO-carousel-propmaker
adding LEGO carousel propmaker project
2 parents b59621d + 71cfced commit 4c7517f

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
819 KB
Binary file not shown.

LEGO_Carousel_PropMaker/code.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: 2024 Noe Ruiz for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import board
6+
import audiocore
7+
import audiobusio
8+
import audiomixer
9+
from digitalio import DigitalInOut, Direction
10+
import pwmio
11+
import neopixel
12+
from adafruit_led_animation.animation.rainbow import Rainbow
13+
from adafruit_motor import servo
14+
15+
# enable external power pin
16+
# provides power to the external components
17+
external_power = DigitalInOut(board.EXTERNAL_POWER)
18+
external_power.direction = Direction.OUTPUT
19+
external_power.value = True
20+
21+
# i2s playback
22+
wave_file = open("carousel-loop.wav", "rb")
23+
wave = audiocore.WaveFile(wave_file)
24+
audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
25+
mixer = audiomixer.Mixer(voice_count=1, sample_rate=22050, channel_count=1,
26+
bits_per_sample=16, samples_signed=True)
27+
audio.play(mixer)
28+
mixer.voice[0].play(wave, loop=True)
29+
30+
# servo control
31+
pwm = pwmio.PWMOut(board.EXTERNAL_SERVO, frequency=5)
32+
prop_servo = servo.ContinuousServo(pwm)
33+
34+
# external neopixels
35+
num_pixels = 43
36+
pixels = neopixel.NeoPixel(board.EXTERNAL_NEOPIXELS, num_pixels)
37+
pixels.brightness = 0.3
38+
rainbow = Rainbow(pixels, speed=0.05, period=2)
39+
40+
while True:
41+
prop_servo.throttle = 1
42+
rainbow.animate()
43+
mixer.voice[0].level = 1

0 commit comments

Comments
 (0)