Nicolas Ruiz
Published

Little Music Box

A little box that makes sounds and raises its pitch when its knob is turned to the side.

BeginnerFull instructions provided3 hours192
Little Music Box

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Toggle Switch, (On)-Off-(On)
Toggle Switch, (On)-Off-(On)
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Code

Code for Box

JavaScript
Once the object is on a green light turns on so it indicates that it's on and a tone plays at half speed, the knob indicates the pitch on what level it is.
let value = 0
pins.A2.setPull(PinPullMode.PullUp)
music.setVolume(128)
forever(function () {
    if (!(pins.A2.digitalRead())) {
        light.setAll(0x00ff00)
        value = pins.A1.analogRead()
        music.playTone(value, music.beat(BeatFraction.Half))
    } else {
        light.clear()
    }
})

Credits

Nicolas Ruiz

Nicolas Ruiz

3 projects • 0 followers

Comments