Maker.io main logo

Labo Piano Light FX

2018-05-16 | By Adafruit Industries

License: See Original Project Circuit Playground

Courtesy of Adafruit

Guide by Collin Cunningham

Overview

Nintendo Labo Toy-Cons are a lot of fun to build, but customizing them is the real icing on the cake. Let's spice up the Piano Toy-Con with sound-triggered lighting effects courtesy of Circuit Playground Express.

 

What you'll need

Wiring

Circuit Playground Express has a built-in microphone, but we'll need to mount it away from the Switch's speakers in order to see our lighting effects. Let's use a separate mic that we can mount close to the Switch's speaker - then use wires to connect it to the Circuit Playground Express.

Prep the wires

circuitpython_labo-0

Cut three pieces of wire - each about 30cm long, one in blue, one in white, and one in red.

Cut three pieces of wire

Strip about 7mm of shielding from both ends of each wire.

Strip 7mm of shielding from both ends of each wire

Tin each exposed end with solder.

Tin each exposed end with solder

Solder wires to the Circuit Playground Express

Now we'll connect those wires to the Circuit Playground's contacts. Each wire color connects to a specific contact pad:

  • Red wire connects to 3.3V
  • Blue wire connects to GND
  • White wire connects to A7

bend the wire around outside of pad to keep in place

Solder wires to the Circuit Playground Express

Poke each tinned wire lead through its corresponding contact pad, bend the wire around the outside of the pad to keep it in place - and then solder it securely.

you can loosely braid the wires in order

At this point, you can loosely braid the wires in order to keep them grouped neatly together. This is optional :)

Solder Wires to the Electret Microphone Amplifier

Next, we'll connect our wiring to the Microphone board. Each wire color connects to a specific pad on the Microphone board. Poke each wire through its respective pad and solder in place:

  • Red wire connects to V
  • Blue wire connects to GND
  • White wire connects to Out

Solder Wires to the Electret Microphone Amplifier

Solder Wires to the Electret Microphone Amplifier

Once each wire is soldered to the board, clip any excess leads off to avoid accidental bridginf between the pads.

That's all for soldering and wiring - now we can move on to programming the board.

Software

Now we'll add the software that will make Circuit Playground Express's neopixels light up whenever the Electret Microphone board detects sound.

Upload the code

Upload the Code

Connect the Circuit Playground Express to your computer with a micro USB cable. You should see a drive named "CIRCUITPY" appear on your computer.

You should see a drive named "CIRCUITPY" appear

You'll need to have the Neopixel library installed on your Circuit Playground Express in order to run this project's CircuitPython code. Follow the steps on this page to install the CircuitPython library bundle.

Installing the CircuitPython Library Bundle

Copy the following code, paste it into a plain text file or code editor such as Mu. Save the file as "code.py" to the CIRCUITPY drive.

Copy Code
import board
import neopixel
import time
from analogio import AnalogIn
import array

n_pixels = 10 # Number of pixels you are using
dc_offset = 0 # DC offset in mic signal - if unusure, leave 0
noise = 100 # Noise/hum/interference in mic signal
lvl = 10 # Current "dampened" audio level
maxbrt = 127 # Maximum brightness of the neopixels (0-255)
wheelStart = 0 # Start of the RGB spectrum we'll use
wheelEnd = 255 # End of the RGB spectrum we'll use

mic_pin = AnalogIn(board.A7)

# Set up NeoPixels and turn them all off.
strip = neopixel.NeoPixel(board.NEOPIXEL, n_pixels, brightness=0.1, auto_write=False)
strip.fill(0)
strip.show()

def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if (pos < 0) or (pos > 255):
return (0, 0, 0)
if (pos < 85):
return (int(pos * 3), int(255 - (pos*3)), 0)
elif (pos < 170):
pos -= 85
return (int(255 - pos*3), 0, int(pos*3))
else:
pos -= 170
return (0, int(pos*3), int(255 - pos*3))

def remapRangeSafe(value, leftMin, leftMax, rightMin, rightMax):
# this remaps a value from original (left) range to new (right) range

# Force the input value to within left min & max
if value < leftMin: value = leftMin
if value > leftMax: value = leftMax

# Figure out how 'wide' each range is
leftSpan = leftMax - leftMin
rightSpan = rightMax - rightMin

# Convert the left range into a 0-1 range (int)
valueScaled = int(value - leftMin) / int(leftSpan)

# Convert the 0-1 range into a value in the right range.
return int(rightMin (valueScaled * rightSpan))

while True:
n = int ( ( mic_pin.value / 65536 ) * 1000 ) # 10-bit ADC format
n = abs(n - 512 - dc_offset) # Center on zero

if ( n >= noise ): # Remove noise/hum
n = n - noise

lvl = int ( ( (lvl * 7) n ) / 8 ) # "Dampened" reading (else looks twitchy) - divide by 8 (2^3)

# Color pixels based on rainbow gradient
vlvl = remapRangeSafe(lvl, 0, 255, wheelStart, wheelEnd)
for i in range(0, len(strip)):
strip[i] = wheel(vlvl)
# Set strip brightness based on audio level
strip.brightness = float(remapRangeSafe(lvl,50,255,0,maxbrt))/255.0
strip.show()

After the file saves, your Circuit Playground Express should reboot and start running the light effects code.

Test It

To make sure everything is working, disconnect the Circuit Playground Express from your computer and connect the LiPo battery.

Test It

Now, try tapping the microphone - If the Circuit Playground's neopixels light up with each tap, then you'll know it's good to go!

Install & Use It!

Now, we just need to install the Circuit Playground Express & Electret Microphone board in the Piano Toy-Con.

Install the mic

Install the Mic

Push back the large cardboard plate that supports the Switch until the interlocking front lip pops up.

Install the mic

Pull the large backing plate forward a bit and slide the microphone board behind it - be sure to keep the silver microphone cylinder facing forward.

Install the mic

Tuck the wires behind the backing plate and route them up the right side - there's a triangular opening that will allow them to reach the Circuit Playground Express on top of the piano.

Install the mic

Install the mic

Once the wires are routed, push the front lip back in place with its tab locked into the backing plate.

Mount the Circuit Playground Express

Use a small piece of double-sided tape to stick the the LiPo battery to the back of the Circuit Playground Express.

Mount the Circuit Playground Express

Mount the Circuit Playground Express

Mount the Circuit Playground Express

Use another piece of tape to secure the LiPo battery and Circuit Playground Express to the top of the piano.

Play - with lights!

Install the right Joy-Con in the holder at the back of the piano and place the Switch console in its spot at the center. Set the Switch's volume all the way up and start up the Piano Play mode in the Labo Variety pack cartridge. Now - you're good to go!

Now, when you play the piano - you'll have a light show with every performance :)

**To preserve battery, remember to disconnect the battery from the Circuit Playground Express when not in use.

制造商零件编号 3333
CIRCUIT PLAYGROUND EXPRESS
Adafruit Industries LLC
制造商零件编号 1028
2.9" RED/BLACK/WHITE EINK DSPLY
Adafruit Industries LLC
制造商零件编号 2001
HOOK-UP 30AWG 600V RED 6.56'
Adafruit Industries LLC
制造商零件编号 2002
HOOK-UP 30AWG 600V BLUE 6.56'
Adafruit Industries LLC
制造商零件编号 2006
HOOK-UP 30AWG 600V WHITE 6.56'
Adafruit Industries LLC
制造商零件编号 3025030-03
CBL USB2.0 A PLUG-MCR B PLUG 3'
Qualtek
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum