# Color Sensing Music Player

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/142/058/medium800/light_hero-scene-1.jpg?1769458374 )

https://youtu.be/iY0OBRoH8_U

Build a fun and playful 3D printed MP3 player with CircuitPython and an RP2040 PropMaker Feather! It's a boombox for young makers, but with a twist: use a color sensor to detect a LEGO DUPLO brick and play a song, sound effect, or audio clip. Each colored brick plays a different audio file.

You can use the Adalogger FeatherWing microSD card slot to add extra media storage to add as many MP3 audio files as you can store!

## 3D Printed Boombox

All of the electronics are housed in a 3D printed enclosure that features a storage bin for holding several DUPLO bricks. It features a 3W 4Ohm mono speaker that connects to the I2S audio amplifier that's built-into the RP2040 PropMaker Feather.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/084/medium640thumb/light_spin.jpg?1769532700)

## Color Sensing Magic

Pop a DUPLO brick into the boombox and click the rotary knob to have it say what color the brick is. You can turn the knob to turn up or down the volume. The on-board NeoPixel LED will light up to the corresponding brick color.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/142/093/medium640thumb/light_colors.jpg?1769533428)

## Detect Different Colors!

This project is configured to detect 11 different colors from the DUPLO brick box. You can add new colors by reading the values from the sensor and assigning a new MP3 file in the code. The code page in this guide will cover how it all works.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/125/medium640/light_hero-brick-colors.jpg?1769543444)

Music featured in this project is by written by&nbsp; **Dan Q** for Adafruit. Check out all of Dan Q's music on the [Adafruit Soundcloud page](https://soundcloud.com/adafruit "Adafruit Soundcloud page").

![](https://cdn-learn.adafruit.com/assets/assets/000/142/162/medium640/light_adafruit_adaloops_icon.jpg?1769607298)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/077/medium800/light_hero-scene-3.jpg?1769531903 )

# Parts
Featured
### Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier

[Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier](https://www.adafruit.com/product/5768)
The Adafruit Feather series gives you lots of options for a small, portable, rechargeable microcontroller board. By picking a feather and stacking on a FeatherWing you can create advanced projects quickly. One popular combo is our [Feather M4](https://www.adafruit.com/product/3857)...

In Stock
[Buy Now](https://www.adafruit.com/product/5768)
[Related Guides to the Product](https://learn.adafruit.com/products/5768/guides)
![Video of a white hand pressing a button to briefly turn an LED strip into white lights. Also wired up to the microcontroller are a servo motor and a speaker.](https://cdn-shop.adafruit.com/product-videos/640x480/5768-09.jpg)

Featured
### Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards

[Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards](https://www.adafruit.com/product/2922)
A Feather board without ambition is a Feather board without FeatherWings! This is the **Adalogger FeatherWing** : it adds both a battery-backed Real Time Clock and micro SD card storage to any Feather main board. Using our [Feather...](https://www.adafruit.com/products/2830)

In Stock
[Buy Now](https://www.adafruit.com/product/2922)
[Related Guides to the Product](https://learn.adafruit.com/products/2922/guides)
![Adalogger FeatherWing with Real time clock and SD card slot.](https://cdn-shop.adafruit.com/640x480/2922-11.jpg)

Featured
### Adafruit AS7341 10-Channel Light / Color Sensor Breakout

[Adafruit AS7341 10-Channel Light / Color Sensor Breakout](https://www.adafruit.com/product/4698)
The **Adafruit AS7341 10-Channel Light / Color Sensor Breakout** is a multi-channel spectrometer, which is a special type of light sensor that is able to detect not only the amount of light present but also the amounts of light within different wavelengths. This means that you can...

In Stock
[Buy Now](https://www.adafruit.com/product/4698)
[Related Guides to the Product](https://learn.adafruit.com/products/4698/guides)
![Angled shot of black, rectangular light sensor breakout.](https://cdn-shop.adafruit.com/640x480/4698-10.jpg)

Featured
### Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder

[Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder](https://www.adafruit.com/product/5880)
Rotary encoders are soooo much fun! Twist em this way, then twist them that way. Unlike potentiometers, they go all the way around and often have little detents for tactile feedback. But, if you've ever tried to add encoders to your project you know that they're a real challenge to...

In Stock
[Buy Now](https://www.adafruit.com/product/5880)
[Related Guides to the Product](https://learn.adafruit.com/products/5880/guides)
![Angled Shot of the I2C Stemma QT Rotary Encoder Breakout with Encoder.](https://cdn-shop.adafruit.com/640x480/5880-00.jpg)

Featured
### Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm

[Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm](https://www.adafruit.com/product/4445)
Listen up! This single&nbsp; 2.8" x 1.2" speaker&nbsp;is&nbsp;the perfect addition to any audio project where you need 4 ohm impedance and 3W or less of power. We particularly like these speakers as they are small and enclosed for good audio volume and quality. This speaker _does..._

In Stock
[Buy Now](https://www.adafruit.com/product/4445)
[Related Guides to the Product](https://learn.adafruit.com/products/4445/guides)
![Enclosed Speaker with wires](https://cdn-shop.adafruit.com/640x480/4445-01.jpg)

Featured
### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

In Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
![Double prototyping feather wing PCB with socket headers installed](https://cdn-shop.adafruit.com/640x480/2890-01.jpg)

Featured
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
![Angled shot of a coiled black, USB-C to USB-A cable.](https://cdn-shop.adafruit.com/640x480/4474-02.jpg)

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long](https://www.adafruit.com/product/4401)
This 4-wire cable is a little over 200mm / 7.8" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4401)
[Related Guides to the Product](https://learn.adafruit.com/products/4401/guides)
![Angled shot of JST SH 4-Pin Cable - 200mm Long.](https://cdn-shop.adafruit.com/640x480/4401-04.jpg)

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

### 512MB micro SD Memory Card

[512MB micro SD Memory Card](https://www.adafruit.com/product/5252)
Add storage in a jiffy using this **512MB** microSD card. Preformatted to FAT32, so it works out of the packaging with our projects. Works great with any device in the Adafruit shop that uses microSD cards. Ideal for use with Feathers, data loggers, or small Linux SBCs (not good...

In Stock
[Buy Now](https://www.adafruit.com/product/5252)
[Related Guides to the Product](https://learn.adafruit.com/products/5252/guides)
![Angel shot of Small microSD card 512mb](https://cdn-shop.adafruit.com/640x480/5252-00.jpg)

### 3x AA Battery Holder with On/Off Switch and 2-Pin JST

[3x AA Battery Holder with On/Off Switch and 2-Pin JST](https://www.adafruit.com/product/4779)
Here's another addition to our growing family of&nbsp;[AA battery holders](https://www.adafruit.com/category/563). Behold! A&nbsp;holder for three (3) AA batteries! It's got&nbsp;a 6" long genuine JST-PH 2-pin cable connector, an On/Off switch, and, oh yes, it's in...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4779)
[Related Guides to the Product](https://learn.adafruit.com/products/4779/guides)
![Angled shot of 3 x AA battery holder with on-off switch and JST SH connector.](https://cdn-shop.adafruit.com/640x480/4779-02.jpg)

### Breadboard-friendly SPDT Slide Switch

[Breadboard-friendly SPDT Slide Switch](https://www.adafruit.com/product/805)
These nice switches are perfect for use with breadboard and perfboard projects. They have 0.1" spacing and snap in nicely into a solderless breadboard. They're easy to switch no matter what size fingers you have, but not so easy that they'll get flipped by accident. Work great as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/805)
[Related Guides to the Product](https://learn.adafruit.com/products/805/guides)
![Small, black, SPDT slide switch.](https://cdn-shop.adafruit.com/640x480/805-03.jpg)

### Silicone Cover Stranded-Core Ribbon Cable - 4 Wires 1 Meter Long

[Silicone Cover Stranded-Core Ribbon Cable - 4 Wires 1 Meter Long](https://www.adafruit.com/product/3891)
For those who are fans of our silicone-covered wires, but are always looking to _up their wiring game_. We now have **Silicone Cover Ribbon cables!** These may look _a lot_ like <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/3891)
[Related Guides to the Product](https://learn.adafruit.com/products/3891/guides)
![4 wire Silicone Cover Stranded-Core Ribbon Cable](https://cdn-shop.adafruit.com/640x480/3891-01.jpg)

### Header Kit for Feather - 12-pin and 16-pin Female Header Set

[Header Kit for Feather - 12-pin and 16-pin Female Header Set](https://www.adafruit.com/product/2886)
These two&nbsp; **Female&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with any of our&nbsp;[Feather](https://www.adafruit.com/categories/777)&nbsp;boards and you're in business!

What do they do? They get soldered on either side of the Feather...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2886)
[Related Guides to the Product](https://learn.adafruit.com/products/2886/guides)
![Angled shot of a Header Kit for Feather - 12-pin and 16-pin Female Header Set. ](https://cdn-shop.adafruit.com/640x480/2886-00.jpg)

## LEGO® DUPLO® Compatible&nbsp;

The project is designed to be compatible with 2x2 DUPLO bricks. The brick box set is a great beginners kit featuring several bricks featuring different colors.

### Part: DUPLO Brick Box #10913
quantity: 1
65pcs build-and-play set with storage box
[DUPLO Brick Box #10913](https://www.lego.com/en-us/product/brick-box-10913)

## Hardware Fasteners

The following fasteners are required to assemble this project.

12x M2.5 x 6mm steel machines crews  
6x M3 x 4mm steel machine screws  
10x M3 x 6mm steel machine screws  
4x M3 x 8mm steel machine screws  
4x M3 steel hex nuts  
2x M5 x 8mm steel machine screws  
2x M5 steel hex nuts

# Color Sensing Music Player

## Circuit Diagram

The diagram below provides a general visual reference for wiring of the components once you get to the **Assembly** page. This diagram was created using the software package [Fritzing](http://fritzing.org/download/).

## Adafruit Library for Fritzing

Adafruit uses the Adafruit Fritzing parts library to create circuit diagrams for projects. You can download the library or just grab individual parts. Get the library and parts from [GitHub - Adafruit Fritzing Parts](https://github.com/adafruit/Fritzing-Library/tree/master/parts).

![](https://cdn-learn.adafruit.com/assets/assets/000/141/912/medium800/light_circuit-diagram.jpg?1768929540 )

## Wired Connections

The PropMaker Feather RP2040 and Adalogger FeatherWing are fitted onto a FeatherWing Doubler.

The AS7341 color sensor is connected to the PropMaker Feather RP2040 via STEMMA QT cable.

The Rotary Encoder is connected to the color sensor via STEMMA QT Cable.

The speaker is connected to the speaker output pins on the PropMaker Feather RP2040 screw block terminals.

The slide switch is connected to the EN (enable) and GND (ground) pins on the FeatherWing Doubler.

The PropMaker Feather RP2040 is powered by a 3x AA battery back.

# Color Sensing Music Player

## Install CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_rp2040_prop_maker/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/121/865/medium800/adafruit_products_boot_reset.jpg?1686710555)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RPI-RP2**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **RPI-RP2.**

![install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/656/medium640/install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg?1618943666)

![install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/657/medium640/install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg?1618943674)

The **RPI-RP2** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/658/medium640/install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg?1618943864)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2](https://cdn-learn.adafruit.com/assets/assets/000/145/511/original/nuke_universal.uf2?1786537992)
# Color Sensing Music Player

## Code the Player

Once you've finished setting up your Feather Prop Maker with CircuitPython, you can access the code, MP3 files and necessary libraries by downloading the Project Bundle.

To do this, click on the **Download Project Bundle** button in the window below. It will download to your computer as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Duplo_Color_Boombox/code.py

## Upload the Code and Libraries to the Feather Prop Maker

After downloading the Project Bundle, plug your Feather Prop Maker into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called **CIRCUITPY**. Unzip the folder and copy the following items to the Feather Prop Maker's **CIRCUITPY** drive.

- **lib** folder
- **code.py**

Your Feather Prop Maker **CIRCUITPY** drive should look like this after copying the **lib** folder&nbsp;and **code.py** file:

![CIRCUITPY drive](https://adafruit.github.io/Adafruit_Learning_System_Guides/Duplo_Color_Boombox.png )

## Add MP3s to microSD Card

Mount the microSD card (FAT formatted) to your computer and add the MP3 audio files from the **/mp3\_files\_for\_sd\_card** folder from the Project Bundle to the root directly of the storage device. After adding the MP3s to the microSD card, remove it from the computer and pop it into the microSD card slot on the Adalogger FeatherWing.

Danger: Make sure the MP3s are added to the microSD card and NOT the SD folder in the CIRCUITPY drive.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/072/medium800/light_sd-card.jpg?1769527284 )

## How the CircuitPython Code Works

At the top of the code, the `EXTERNAL_POWER` pin is enabled to power up the peripherals on the Feather.

```python
#Power Setup
external_power = DigitalInOut(board.EXTERNAL_POWER)
external_power.direction = Direction.OUTPUT
external_power.value = True
```

### SD Card

The SD card is set up using `sdcardio` and is mounted to the **/sd** mount point. The mount point is set to `readonly` within CircuitPython so that it can be read/write on your OS when the CircuitPython drive is mounted. This means that you can drag and drop audio files to the SD card over USB.

```python
#SD Card setup

spi = board.SPI()
cs = board.D10
sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
```

### Audio

Next is the audio setup. For this project, MP3 audio files are used. The MP3 decoder and built-in I2S output are passed to a&nbsp;`Mixer` object. This lets you control the volume via software.

```python
#Audio
mp3 = audiomp3.MP3Decoder(open("/sd/blue.mp3", "rb"))

i2s = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
mixer = audiomixer.Mixer(voice_count=1, sample_rate=mp3.sample_rate, channel_count=1,
                         bits_per_sample=mp3.bits_per_sample)
i2s.play(mixer)
mixer.voice[0].level = 0.5
```

### Color Sensor

The color sensor is instantiated over I2C and its white LED is turned off by default.

```python
#Color Sensor
i2c = board.STEMMA_I2C()
sensor = AS7341(i2c)
sensor.led_current = 4  # increments in units of 4
sensor.led = False
```

A dictionary is used to hold each Duplo brick's MP3 audio file name, color reading and NeoPixel color. You can add or edit entries to the dictionary for additional bricks or to change up the associated MP3.

```python
brick_dictionary = [
    {'song': "/sd/blue.mp3", 'value': (1619, 13852, 19215, 18562, 12912, 8818, 9512, 5440),
     'color': ((0, 255, 255))},
    {'song': "/sd/orange.mp3", 'value': (2517, 3983, 5661, 6864, 16857, 39049, 55151, 35696),
     'color': ((255, 60, 0))},
    {'song': "/sd/coral.mp3", 'value': (3004, 6712, 7499, 7160, 13858, 46007, 65535, 39278),
     'color': ((250, 50, 50))},
    {'song': "/sd/purple.mp3", 'value': (2562, 20704, 19222, 15806, 16624, 18399, 27316, 22525),
     'color': ((125, 0, 255))},
    {'song': "/sd/red.mp3", 'value': (1453, 2629, 4050, 4656, 5527, 13403, 31096, 21368),
     'color': ((255, 0, 0))},
    {'song': "/sd/yellow.mp3", 'value': (3051, 4446, 8633, 17412, 37450, 48224, 56249, 34726),
     'color': ((255, 150, 0))},
    {'song': "/sd/butter.mp3", 'value': (4102, 8631, 13692, 29000, 58147, 63230, 65535, 43143),
     'color': ((255, 255, 0))},
    {'song': "/sd/green.mp3", 'value': (1383, 2767, 5850, 12964, 22118, 16304, 12669, 7008),
     'color': ((120, 255, 0))},
    {'song': "/sd/lime.mp3", 'value': (3017, 8109, 17948, 36761, 48754, 38009, 31671, 19457),
     'color': ((150, 255, 0))},
    {'song': "/sd/lightblue.mp3", 'value': (4188, 29507, 42326, 53214, 54067, 37512, 34129, 23544),
     'color':((100, 250, 255))},
    {'song': "/sd/white.mp3", 'value': (5246, 27506, 33883, 44702, 62766, 64254, 65535, 48334),
     'color':((255, 255, 255))},
    ]
```

A function called `find_closest_brick()` is used to determine if the Duplo brick that is held up to the color sensor matches one of the defined colors in the dictionary. Since the color readings are analog and can vary depending on external light, the function returns the closest match to the current reading. If there isn't a close enough match, it returns `None`. You can change the sensitivity by adjusting the `max_distance` value.

```python
def find_closest_brick(reading, dictionary, max_distance=50000):
    """
    Find the brick with the closest matching sensor values.

    Args:
        new_reading: Tuple of 8 sensor values
        brick_dictionary: List of brick dictionaries
        max_distance: Maximum distance to consider a valid match

    Returns:
        Tuple of (matched_brick, distance) or (None, distance) if no good match
    """
    best_match = None
    best_distance = float('inf')

    for brick in dictionary:
        # Calculate total distance (sum of absolute differences)
        distance = sum(abs(v1 - v2) for v1, v2 in zip(reading, brick['value']))

        if distance < best_distance:
            best_distance = distance
            best_match = brick

    # Only return a match if it's close enough
    if best_distance > max_distance:
        return None

    return best_match
```

### Rotary Encoder

The seesaw rotary encoder is next. The built-in switch is used in the code, along with the NeoPixel.

```python
#Rotary STEMMA I2C
seesaw = seesaw.Seesaw(i2c, 0x36)
encoder = rotaryio.IncrementalEncoder(seesaw)
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
switch = digitalio.DigitalIO(seesaw, 24)
switch_state = False

pixel = neopixel.NeoPixel(seesaw, 6, 1)
pixel.brightness = 1
pixel.fill((0, 0, 0))
```

### States and Variables

There are a few variables and states that are used in the loop:

- `last_position` - tracks the last position of the rotary encoder
- `volume` - volume for the audio output through the Mixer object
- `play` - state to track if a song has started playing
- `play_state` - state to track if a song is actually playing or is paused\

Right before the loop, the **boot.mp3** file is played through the speaker.

```python
last_position = -1
volume = 0.5 # volume
play = False
play_state = False

mp3 = audiomp3.MP3Decoder(open("/sd/boot.mp3", "rb"))
mixer.voice[0].play(mp3, loop=False)
```

### The Loop

In the loop, the rotary encoder position is monitored. If the position increases, the volume increases. If it decreases, the volume decreases.

```python
while True:

    # make clockwise rotation positive
    position = -encoder.position

    if position != last_position:
        if position > last_position:
            #decrease volume
            volume = volume - 0.05
            volume = max(volume, 0)
        else:
            #increase volume
            volume = volume + 0.05
            volume = min(volume, 1)
        # set the audio volume
        mixer.voice[0].level = volume
        print(volume)
        last_position = position
```

Pressing the rotary encoder button initiates the color sensor to get a reading. The sensor LED turns on, gets a reading on all channels and passes the reading to the `find_closest_brick()` function. If the code finds a match, then it starts playing the associated MP3 file and lights up the NeoPixel with the associated color.

If a song is currently playing and the button is pressed, then the button toggles play/pause.

When the mixer is no longer playing the song, it resets `play` and `play_state` to `False` and turns off the NeoPixel.

```python
if not switch.value and not switch_state:
        print("Button pressed")
        switch_state = True
        if not play:
            sensor.led = True
            sensor_color = sensor.all_channels
            matched_brick = find_closest_brick(sensor_color, brick_dictionary)
            print(sensor_color)
            if matched_brick is not None:
                print(matched_brick['song'])
                mp3 = audiomp3.MP3Decoder(open(matched_brick['song'], "rb"))
                pixel.fill(matched_brick['color'])
                play = True
                mixer.voice[0].play(mp3, loop=False)
                play_state = True
            else:
                print("insert brick")
                mp3 = audiomp3.MP3Decoder(open("/sd/uhoh.mp3", "rb"))
                mixer.voice[0].play(mp3, loop=False)
        else:
            if play_state:
                i2s.pause()
                play_state = False
            else:
                i2s.resume()
                play_state = True
    if switch.value and switch_state:
        sensor.led = False
        switch_state = False
        print("Button released")

    if not mixer.playing:
        play_state = False
        play = False
        pixel.fill((0,0,0))
```

# Color Sensing Music Player

## 3D CAD Files

## 3D Printed Parts

Individual 3MF files for 3D printing are oriented and ready to print on FDM machines using PLA filament. Original design source files may be downloaded using the links below.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/962/medium640/light_3d-parts.jpg?1769195692)

[3mf.zip](https://cdn-learn.adafruit.com/assets/assets/000/142/098/original/3mf.zip?1769533619)
[CAD.zip](https://cdn-learn.adafruit.com/assets/assets/000/142/099/original/CAD.zip?1769533836)
## CAD Assembly

The Doubler FeatherWing is secured to the back cover using screws.

The back cover snap fits onto the case frame.

The rotary encoder, color sensor and speaker are secured to individual mounting plates which are attached to the front plate using screws.&nbsp;

The front plate is secured to the case framing with more screws.&nbsp;

The storage bin is fitted and sandwiched in between the back cover and case framing.&nbsp;

The handle is secured to the case framing using screws.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/054/medium640/light_cad-assembly-cropped.jpg?1769451945)

## Build Volume

The parts require a 3D printer with a minimum build volume of 100 (X) x 70mm (Y) x 158mm (Z).

![](https://cdn-learn.adafruit.com/assets/assets/000/142/055/medium640/light_build-plate.jpg?1769452421)

## Support Material

The duplo knob requires support material. Use your preferred slice settings for supports or reference the settings below.

- Support Type: Tree
- Branch distance: 5mm
- Branch diameter: 6mm
- Top interface layer: 2

![](https://cdn-learn.adafruit.com/assets/assets/000/142/057/medium640/light_supports-knob.jpg?1769453629)

## Design Source Files

The project assembly was designed in Fusion 360. Once opened in Fusion 360, It can be exported in different formats like STEP, STL and more.

Electronic components like Adafruit's boards, displays, connectors and more can be downloaded from the&nbsp;[Adafruit CAD parts GitHub Repo](https://github.com/adafruit/Adafruit_CAD_Parts/).

![](https://cdn-learn.adafruit.com/assets/assets/000/142/056/medium640/light_5768-Feather-RP2040-PropMaker.jpg?1769452952)

# Color Sensing Music Player

## Feather Headers Setup

If you need a better explanation for soldering the headers for Feather products, you can review the guide below for tips and tricks.

### How To Solder Headers - Feathers and FeatherWings

[How To Solder Headers](https://learn.adafruit.com/how-to-solder-headers)
[Feathers and FeatherWings](https://learn.adafruit.com/how-to-solder-headers/feathers-and-featherwings)
## Headers

Gather up the headers needed for the Feather, Adalogger FeatherWing, and Doubler.

- 2x 12-pin male headers
- 2x 16-pin male headers
- 2x 12-pin female headers
- 2x 16-pin female headers

![](https://cdn-learn.adafruit.com/assets/assets/000/141/920/medium640/light_headers.jpg?1769023680)

## Install Adalogger FeatherWing

Use a breadboard to help keep the headers straight while soldering.

Fit the 12-pin and 16-pin male header pins onto the bottom of the Adalogger FeatherWing PCB.

Solder all of the pins in place. Remove the Feather carefully from the breadboard when finished.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/921/medium640/light_adalogger-headers.jpg?1769023719)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/922/medium640/light_adalogger-soldered.jpg?1769023765)

## Install Feather Headers

Use a breadboard to help keep the headers straight while soldering.

Fit the 12-pin and 16-pin male header pins onto the bottom of the Feather RP2040 PropMaker PCB.

Solder all of the pins in place. Remove the Feather carefully from the breadboard when finished.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/923/medium640/light_propmaker-headers.jpg?1769023785)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/924/medium640/light_propmaker-soldered.jpg?1769023803)

## Install Double Headers

Fit the 12-pin and 16-pin female headers onto the male headers that are soldered on the Feather and FeatherWing.

Then, place the female headers onto the top of the FeatherWing Doubler, making sure the pins are inserted in the correct location.

Keep the pins in place while soldering all of the pins together.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/925/medium640/light_female-headers-install.jpg?1769023855)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/926/medium640/light_doubler-headers.jpg?1769023896)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/927/medium640/light_doubler-headers-soldered.jpg?1769023939)

## Installed Headers

Remove the Feather RP2040 PropMaker and Adalogger FeatherWing from the FeatherWing Doubler.&nbsp;

Make sure all of the headers have sufficient solder and strong joints.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/928/medium640/light_boards-headers-soldered.jpg?1769024026)

## Disable Lipo Charging

Use a sharp hobby knife to cut the LiPo Charging trace on the back of the PropMaker Feather RP2040. This must be cut to prevent accidental battery calamity with alkaline batteries when USB is plugged in.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/963/medium640/light_feather-cut-trace.jpg?1769195902)

Yellow: Be careful when using a hobby knife to cut the trace to insure you are safe and only the part you want to cut is cut and nothing else.

## Disable LED on Sensor

Use a sharp hobby knife to cut the LED trace on the back of the AS7341 light sensor. This needs to be cut to prevent accidental color sensing light leaking from the green LED.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/964/medium640/light_color-sensor-cut-trace.jpg?1769195992)

# Color Sensing Music Player

## Wiring the Switch

If you are unsure about your soldering skills, there is an excellent guide to help:

### Adafruit Guide To Excellent Soldering - Tools

[Adafruit Guide To Excellent Soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering)
[Tools](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools)
## Slide Switch Wires

Prepare a set of two wires about 3.5inches (9cm) in length.

Using wire strippers, remove a bit of insulation from the tips of each wire.

Tin the exposed wire by applying a bit of solder to them.

This will help prevent the strands of wire from fraying.

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/141/950/medium640/light_switch-wires.jpg?1769175495)

## Prep the Slide Switch

Snip off one of the leads on the slide switch, either the far left or right but not the middle. Then trim the two remaining leads short, about half their length.

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/141/951/medium640/light_switch-wire-prep.jpg?1769175526)

Yellow: Be sure to wear eye protection when cutting small bits of metal which may fly in unpredictable directions.

## Solder Wires

Solder the two wires to each of the leads on the slide switch.

A [pair of helping hands](https://www.adafruit.com/product/291) can assist while soldering wires in place.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/952/medium640/light_switch-wire-solder.jpg?1769175544)

## Connect Switch to Doubler FeatherWing

Solder one wire to a ground pin on the Doubler FeatherWing.

Then, solder the remaining wire to the EN (enable) pin.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/953/medium640/light_switch-doubler-solder.jpg?1769175574)

## Soldered Switch

Double check the wires from the slider have been soldered to the correct pins on the Doubler FeatherWing.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/954/medium640/light_doubler-switch.jpg?1769175662)

## Switch Power Test

Test the slide switch by connecting the Feather RP2040 PropMaker to the Doubler FeatherWing.

Install 3x AA batteries into the AA battery holder.&nbsp;

Plug in the cable from the AA battery pack. Ensure the built-in switch is on the ON position.

Use the slide switch to power on the Feather.

The Feather on-board NeoPixel LED should light up indicating it is getting power.

Then use the slide switch to power off the Feather.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/955/medium640/light_switch-battery-test.jpg?1769175736)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/049/medium640/light_AA-batteries.jpg?1769443016)

# Color Sensing Music Player

## Assembly

## Install Doubler

Use 4x M2.5x 6mm long machine screws to secure the Doubler FeatherWing to the back cover.

Place the Doubler PCB over the four standoffs on the back cover.

Insert and fasten the M2.5 to secure the Doubler FeatherWing to the back cover.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/965/medium640/light_back-doubler-screws.jpg?1769196045)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/966/medium640/light_back-double-fasten.jpg?1769196161)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/967/medium640/light_back-double-secured.jpg?1769196210)

## Set Up the Switch Holder

Insert the slide switch into the switch holder at an angle.

Then firmly press the body of the switch so it sets flush with the surfaces of the holder.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/968/medium640/light_switch-holder.jpg?1769196332)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/969/medium640/light_switch-holder-installing.jpg?1769196371)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/970/medium640/light_switch-holder-installed.jpg?1769196417)

## Secure the Switch Holder

Use two M3 x 4mm long machine screws to secure the switch holder to the back cover.

Place the switch holder over the cutout for the switch with the two mounting holes lined up.

Insert and fasten the M3 screws to secure the switch holder to the back cover.

The slide switch actuator should be accessible on the other side of the back cover.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/971/medium640/light_back-switch-holder-screws.jpg?1769196467)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/972/medium640/light_back-switch-holder-fasten.jpg?1769197300)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/973/medium640/light_back-switch-installed.jpg?1769197569)

## Install the Adalogger FeatherWing

Insert the microSD card into the microSD card slot on the Adalogger FeatherWing.

Install the Adalogger FeatherWing onto the upper section on the Doubler FeatherWing.

Firmly press down to fully seat the PCB.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/974/medium640/light_adalogger-sd-card.jpg?1769196716)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/975/medium640/light_adalogger-doubler-install.jpg?1769197932)

## Install Feather

With the battery connected to the Feather RP2040 PropMaker, fit it onto the remaining section on the Doubler FeatherWing.

Firmly press down to fully seat the PCB.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/976/medium640/light_feather-battery-connect.jpg?1769196831)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/977/medium640/light_feather-doubler-install.jpg?1769196854)

## Install Battery

Place the AA battery holder onto the back cover in between the four walls.

Slide the battery clip over the battery holder so the keyed edge is fitted in between the rails on the back cover.

Ensure the battery clip is fitted correctly and the battery holder is secured to the back cover.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/978/medium640/light_battery-back-install.jpg?1769196866)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/979/medium640/light_battery-clip.jpg?1769198215)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/980/medium640/light_battery-clip-installing.jpg?1769198534)

## Speaker Plate

Use four M3 x 8mm long machine screws and hex nuts to secure the speaker to the speaker plate.

Place the speaker plate over the speaker with the mounting holes lined up.

While holding the two in place, insert a machine screw and thread a hex nut to secure them together.

Repeat for all four mounting holes.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/981/medium640/light_speaker-plate-screws.jpg?1769197191)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/982/medium640/light_speaker-plate-fasten.jpg?1769197418)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/983/medium640/light_speaker-plate-secured.jpg?1769197527)

## Install the Color Sensor

Use four M2.5 x 6mm long machine screws to secure the color sensor to the sensor mounting plate.

Place the color sensor over the four standoffs so the mounting holes are lined up.&nbsp;

While holding parts together, insert and fasten the machine screws to secure them together.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/984/medium640/light_sensor-plate-screws.jpg?1769197682)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/985/medium640/light_sensor-plate-fasten.jpg?1769197812)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/986/medium640/light_sensor-plate-secured.jpg?1769197949)

## Rotary Mounting Plate

Remove the washer and hex nut from the rotary encoder.

Insert the shaft of the rotary encoder through the hole in the rotary mounting plate.

Orient the PCB so the STEMMA QT connectors are lined up with the notches on the wall of the mounting plate.

Insert the washer over the shaft and thread the hex nut.

Firmly tighten the hex nut to secure the rotary encoder to the mounting plate.

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/141/987/medium640/light_rotary-plate-screw.jpg?1769198042)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/988/medium640/light_rotary-plate-installing.jpg?1769198119)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/989/medium640/light_rotary-plate-fasten.jpg?1769198154)

## Front Plate Installation

Orient the front plate with the case frame.

Insert the front place into the case frame. Firmly press down so the front plate sits flush with the case frame.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/990/medium640/light_case-front.jpg?1769198270)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/991/medium640/light_case-front-installing.jpg?1769198292)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/992/medium640/light_case-front-installed.jpg?1769198380)

## Secure the Front Plate

Use six M3 x 6mm long machine screws to secure the front plate to the case frame.

Insert and fasten six M3 screws to secure the front plate to the case frame.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/993/medium640/light_case-front-screws.jpg?1769198501)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/994/medium640/light_case-front-fasten.jpg?1769198523)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/995/medium640/light_case-front-secured.jpg?1769198712)

## Secure Speaker Plate

Use for M3 x 4mm long machine screws to secure the speaker mounting plate to the front plate.

Place the speaker mounting plate over the speaker standoffs on the front plate.

While holding parts together, insert and fasten the screws to secure the parts together.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/996/medium640/light_speaker-plate-case-screws.jpg?1769198875)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/997/medium640/light_speaker-plate-case-fasten.jpg?1769199011)

## Connect STEMMA QT

Get the two STEMMA QT cables ready to connect to the rotary encoder and color sensor.

Connect the longer STEMMA QT cable to the left side of the color sensor.&nbsp;

Use the shorter STEMMA QT cable to connect the color sensor to the rotary encoder.

![](https://cdn-learn.adafruit.com/assets/assets/000/141/998/medium640/light_stemma-cables.jpg?1769199031)

![](https://cdn-learn.adafruit.com/assets/assets/000/141/999/medium640/light_sensor-rotary-stemma-connect.jpg?1769199148)

## Secure the Color Sensor

Place the color sensor mounting plate over the sensor standoffs on the front plate.

While holding the mounting plate in place, insert and fasten four M2.5 x 6mm long machine screws to secure the sensor mount to the front plate.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/000/medium640/light_sensor-case-screws.jpg?1769199325)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/001/medium640/light_sensor-case-install.jpg?1769199483)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/002/medium640/light_sensor-case-fasten.jpg?1769199645)

## Secure Rotary Plate

Place the rotary mounting plate over the remaining standoffs on the front plate.

While holding the plate in place, insert and fasten four M3 x 6mm long machine screws to secure the rotary mount to the front plate.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/003/medium640/light_rotary-case-screws.jpg?1769199772)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/004/medium640/light_rotary-case-install.jpg?1769199873)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/005/medium640/light_rotary-case-fasten.jpg?1769200022)

## Check all the Parts

Double check all of the mounting plates are sitting flush with the front plate and all of the screws are fully tightened.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/006/medium640/light_rotary-case-secured.jpg?1769200123)

## Install the Handle

Use two M5 x 8mm machine screws and hex nuts to secure the handle to the case frame.

Slide the handle over the case frame so the two mounting holes line up.

While holding parts, insert and fasten the screws to secure the handle to the case.

Insert and thread the M5 hex nuts to the screws.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/007/medium640/light_handle-case-screws.jpg?1769200172)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/008/medium640/light_handle-case-fasten.jpg?1769200193)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/009/medium640/light_handle-case-nuts.jpg?1769200214)

## Tighten the Handle

Ensure the hex nuts are fully seated. Use a pair of vise grips or pliers to fully tighten the hex nuts.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/010/medium640/light_handle-case-secured.jpg?1769200260)

## Connecting the Speaker

Insert the two colored wires from the speaker into the speaker pins on the Feather RP2040 PropMaker.

Use a slotted screw driver to secure the speaker wires to the screw block terminals.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/011/medium640/light_feather-speaker-connect.jpg?1769200405)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/012/medium640/light_feather-speaker-secured.jpg?1769200423)

## Connect the STEMMA QT Cable

Plug in the longer STEMMA QT cable to the connector on the Feather RP2040 PropMaker.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/013/medium640/light_feather-stemma-connect.jpg?1769200483)

## Connected Parts

Double check the cables are secured.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/014/medium640/light_back-assembled.jpg?1769200491)

## Install the Storage Bin

Slide the storage bin into the case frame so the walls are fitted in between the ridges of the storage bin.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/015/medium640/light_storage-case-installing.jpg?1769200583)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/016/medium640/light_storage-case-installed.jpg?1769200620)

## Install the Back Cover

Begin fitting the back cover over the case framing, making sure the cables are fitted inside.

Firmly press the back cover onto the case to snap fit them closed.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/017/medium640/light_back-case-installing.jpg?1769200719)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/018/medium640/light_back-case-install.jpg?1769200889)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/019/medium640/light_back-case-secured.jpg?1769200960)

## Install the Knob

Orient the rotary knob with the shaft of the rotary encoder.

Line up the flat edges while inserting the knob.

Firmly press the knob to fully seat the parts together.

Test the knob by rotating, ensuring it moves ok.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/050/medium640/light_rotary-knob.jpg?1769450983)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/051/medium640/light_rotary-knob-install.jpg?1769451061)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/052/medium640/light_rotary-knob-test.jpg?1769451110)

## Power Test

Use the slide switch to power on the Feather RP2040 PropMaker.

Test the color sensor by inserting a Duplo brick and pressing the rotary encoder knob. The LED should change color to the color of the brick used.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/020/medium640/light_switch-back-turnon.jpg?1769201029)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/021/medium640/light_demo-test.jpg?1769201174)

## Storing Bricks

Use the storage bin to hold a few Duplo bricks.&nbsp;

Stacked bricks (5 in total) can be fitted into the storage bin.

![](https://cdn-learn.adafruit.com/assets/assets/000/142/022/medium640/light_storage-bricks.jpg?1769201281)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/023/medium640/light_storage-bricks-fit.jpg?1769201312)

![](https://cdn-learn.adafruit.com/assets/assets/000/142/053/medium800/light_finail-build.jpg?1769451719 )

## The Finished Build

Congratulations on your build! The projects code is set to read 11 colors, which are included with the Duplo brick box starter set.&nbsp;&nbsp;

# Color Sensing Music Player

## Use

## Playing MP3s

1. Insert a DUPLO brick into the color sensing area.
2. Click rotary encoder to play MP3.
3. The built-in NeoPixel lights up to corresponding brick color.

While playing audio, click the rotary knob to pause/play. Turn rotary knob to increase/decrease the volume.

If no brick is detected, an audible "Uh Oh" sound will be played.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/142/095/medium640thumb/light_demo.jpg?1769533461)


## Guide Products

### Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier

[Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier](https://www.adafruit.com/product/5768)
The Adafruit Feather series gives you lots of options for a small, portable, rechargeable microcontroller board. By picking a feather and stacking on a FeatherWing you can create advanced projects quickly. One popular combo is our [Feather M4](https://www.adafruit.com/product/3857)...

In Stock
[Buy Now](https://www.adafruit.com/product/5768)
[Related Guides to the Product](https://learn.adafruit.com/products/5768/guides)
### Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards

[Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards](https://www.adafruit.com/product/2922)
A Feather board without ambition is a Feather board without FeatherWings! This is the **Adalogger FeatherWing** : it adds both a battery-backed Real Time Clock and micro SD card storage to any Feather main board. Using our [Feather...](https://www.adafruit.com/products/2830)

In Stock
[Buy Now](https://www.adafruit.com/product/2922)
[Related Guides to the Product](https://learn.adafruit.com/products/2922/guides)
### Adafruit AS7341 10-Channel Light / Color Sensor Breakout

[Adafruit AS7341 10-Channel Light / Color Sensor Breakout](https://www.adafruit.com/product/4698)
The **Adafruit AS7341 10-Channel Light / Color Sensor Breakout** is a multi-channel spectrometer, which is a special type of light sensor that is able to detect not only the amount of light present but also the amounts of light within different wavelengths. This means that you can...

In Stock
[Buy Now](https://www.adafruit.com/product/4698)
[Related Guides to the Product](https://learn.adafruit.com/products/4698/guides)
### Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder

[Adafruit I2C Stemma QT Rotary Encoder Breakout with Encoder](https://www.adafruit.com/product/5880)
Rotary encoders are soooo much fun! Twist em this way, then twist them that way. Unlike potentiometers, they go all the way around and often have little detents for tactile feedback. But, if you've ever tried to add encoders to your project you know that they're a real challenge to...

In Stock
[Buy Now](https://www.adafruit.com/product/5880)
[Related Guides to the Product](https://learn.adafruit.com/products/5880/guides)
### Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm

[Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm](https://www.adafruit.com/product/4445)
Listen up! This single&nbsp; 2.8" x 1.2" speaker&nbsp;is&nbsp;the perfect addition to any audio project where you need 4 ohm impedance and 3W or less of power. We particularly like these speakers as they are small and enclosed for good audio volume and quality. This speaker _does..._

In Stock
[Buy Now](https://www.adafruit.com/product/4445)
[Related Guides to the Product](https://learn.adafruit.com/products/4445/guides)
### FeatherWing Doubler - Prototyping Add-on For All Feather Boards

[FeatherWing Doubler - Prototyping Add-on For All Feather Boards](https://www.adafruit.com/product/2890)
This is the **FeatherWing Doubler** - a prototyping add-on and more for all Feather boards. This is similar to our [FeatherWing Proto](https://www.adafruit.com/products/2884) except there are two! The magic of the Doubler comes when stacking a Feather and another...

In Stock
[Buy Now](https://www.adafruit.com/product/2890)
[Related Guides to the Product](https://learn.adafruit.com/products/2890/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 200mm Long](https://www.adafruit.com/product/4401)
This 4-wire cable is a little over 200mm / 7.8" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4401)
[Related Guides to the Product](https://learn.adafruit.com/products/4401/guides)

## Related Guides

- [Adafruit I2C QT Rotary Encoder](https://learn.adafruit.com/adafruit-i2c-qt-rotary-encoder.md)
- [Adafruit RP2040 Prop-Maker Feather](https://learn.adafruit.com/adafruit-rp2040-prop-maker-feather.md)
- [MagTag Literary Quote Clock](https://learn.adafruit.com/magtag-literary-quote-clock.md)
- [Neocontroller Color Grading Input Box](https://learn.adafruit.com/neocontroller-color-grading-input-box.md)
- [Commodore Keyboard to USB HID with CircuitPython](https://learn.adafruit.com/commodore-keyboard-to-usb-hid-with-circuitpython.md)
- [Programmable Wireless BLE Gesture Mouse](https://learn.adafruit.com/ble-wireless-gesture-mouse.md)
- [MagTag Dishwasher Status](https://learn.adafruit.com/magtag-dishwasher-status.md)
- [RGB Matrix Portal Room CO2 Monitor](https://learn.adafruit.com/matrix-portal-room-co2-monitor.md)
- [Create a Memory Game on Fruit Jam Metro RP2350](https://learn.adafruit.com/create-a-memory-game-on-metro-rp2350.md)
- [World Clock](https://learn.adafruit.com/world-clock.md)
- [LED Noodle Lamp](https://learn.adafruit.com/led-noodle-lamp.md)
- [Retroreflective Greenscreen Light Ring QT Py Controller ](https://learn.adafruit.com/retroreflective-green-screen-light-ring-controller.md)
- [MagTag 3D Printed Stand Case](https://learn.adafruit.com/magtag-3d-printed-stand-case.md)
- [NeoPixel Remote: IR Control with WLED](https://learn.adafruit.com/neopixel-remote-ir-control-with-wled.md)
- [Light Up your Costume with Noods](https://learn.adafruit.com/light-up-your-costume-with-noods.md)
- [NeoPixel Flame Torch](https://learn.adafruit.com/neopixel-flame-torch.md)
- [Haunted Air Blaster](https://learn.adafruit.com/automated-air-blaster.md)
