Skip to content

Commit a5e63d8

Browse files
committed
adding LEGO carousel propmaker project
adding files for LEGO carousel propmaker project
1 parent b59621d commit a5e63d8

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

819 KB
Binary file not shown.

LEGO_Carousel_PropMaker/code.py

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

0 commit comments

Comments
 (0)