Derek GilbertiCasey N.Soje RiversBen Wilcox
Created November 15, 2021

One Man Band

A "Drum box" that acts as a small music instrument for the user and a "Saxophone" that plays the melody.

20
One Man Band

Things used in this project

Story

Read more

Schematics

Drum Audio

zip file of the drum samples (for the drum)

Saxophone Audio

Compressed Audio for the Saxophone

Code

code.py (Drum)

Python
The code used in the Drum portion of the instrument, set up on a playground express circuit board.
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""THIS EXAMPLE REQUIRES A WAV FILE FROM THE examples FOLDER IN THE
Adafruit_CircuitPython_CircuitPlayground REPO found at:
https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/main/examples

Copy the "kick.wav" and "snare.wav" files to your CIRCUITPY drive.

Once the files are copied, this example plays a different drum sound for each button pressed!"""
from adafruit_circuitplayground import cp

cp.pixels.brightness = 0.3
cp.pixels.fill((0, 0, 0))  # Turn off the NeoPixels if they're on!

while True:
    if cp.button_a:
        cp.play_file("kick.wav")
    if cp.button_b:
        cp.play_file("snare.wav")

    if cp.button_a:
        cp.pixels[0:5] = [(255, 0, 0)] * 5
    else:
        cp.pixels[0:5] = [(0, 0, 0)] * 5

    if cp.button_b:
        cp.pixels[5:10] = [(0, 255, 0)] * 5
    else:
        cp.pixels[5:10] = [(0, 0, 0)] * 5

code.py (Saxophone)

Python
Python code for the Saxophone. Should be connected to an playground express circuit.
from adafruit_circuitplayground import cp

import time
import board
from analogio import AnalogIn

analog_in = AnalogIn(board.A1)


def get_voltage(pin):
    return (pin.value * 3.3) / 65536

while True:
    if cp.button_a:
        if (get_voltage(analog_in)) <= 0.25384615384:
            cp.play_file("c.wav")
        if (get_voltage(analog_in)) > 0.2538461538 and (get_voltage(analog_in)) <= 0.5076923076:
            cp.play_file("c#.wav")
        if (get_voltage(analog_in)) > 0.50769230768 and (get_voltage(analog_in)) <= 0.76153846152:
            cp.play_file("d.wav")
        if (get_voltage(analog_in)) > 0.76153846152 and (get_voltage(analog_in)) <= 1.01538461536:
            cp.play_file("d#.wav")
        if (get_voltage(analog_in)) > 1.01538461536 and (get_voltage(analog_in)) <= 1.2692307692:
            cp.play_file("e.wav")
        if (get_voltage(analog_in)) > 1.2692307692 and (get_voltage(analog_in)) <= 1.52307692304:
            cp.play_file("f.wav")
        if (get_voltage(analog_in)) > 1.52307692304 and (get_voltage(analog_in)) <= 1.77692307688:
            cp.play_file("f#.wav")
        if (get_voltage(analog_in)) > 1.77692307688 and (get_voltage(analog_in)) <= 2.03076923072:
            cp.play_file("g.wav")
        if (get_voltage(analog_in)) > 2.03076923072 and (get_voltage(analog_in)) <= 2.28461538456:
            cp.play_file("g#.wav")
        if (get_voltage(analog_in)) > 2.28461538456 and (get_voltage(analog_in)) <= 2.5384615384:
            cp.play_file("a.wav")
        if (get_voltage(analog_in)) > 2.5384615384 and (get_voltage(analog_in)) <= 2.79230769224:
            cp.play_file("a#.wav")
        if (get_voltage(analog_in)) > 2.79230769224 and (get_voltage(analog_in)) <= 3.04615384608:
            cp.play_file("b.wav")
        if (get_voltage(analog_in)) > 3.04615384608 and (get_voltage(analog_in)) <= 3.3:
            cp.play_file("c (up).wav")
    print((get_voltage(analog_in),))
    time.sleep(0.1)

Credits

Derek Gilberti
4 projects • 1 follower
Contact
Casey N.
4 projects • 1 follower
Contact
Soje Rivers
4 projects • 0 followers
Contact
Ben Wilcox
4 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.