Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Jake Vaughan
Published

Make-It-Beep_Radio

Uses potentiometer to control volume of pitch and tweak randomization of melody played.

BeginnerShowcase (no instructions)39
Make-It-Beep_Radio

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Alligator Clips
Alligator Clips
×9
Toggle Switch, Toggle
Toggle Switch, Toggle
×2
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Hand tools and fabrication machines

Scissor, Electrician
Scissor, Electrician

Story

Read more

Schematics

Starting Box

Box

Wired Up Board

Playground Express Board wired up with alligator clips

Painted Box

Box post painting black

Black Box with Gear

Blackboard with Switches and Potentiometer inserted in. Power switch at top, Volume < --- > Play potentiometer switch in the center. Potentiometer at the bottom.

Code

Code For Project

JavaScript
Uses switch on A1 to turn device on or off. Uses switch on A2 to switch between having the potentiometer on A3 control setting volume and playing a melody. When the potentiometer is controlling playing a melody, the melody played is randomized with constraints based on the value the potentiometer is set to.
function ChooseAMelodyKey (ran: number) {
    if (ran == 1) {
        list.push("C")
    } else {
        if (ran == 2) {
            list.push("D")
        } else {
            if (ran == 3) {
                list.push("E")
            } else {
                if (ran == 4) {
                    list.push("F")
                } else {
                    if (ran == 5) {
                        list.push("G")
                    } else {
                        if (ran == 6) {
                            list.push("A")
                        } else {
                            if (ran == 7) {
                                list.push("B")
                            } else {
                                list.push("C5")
                            }
                        }
                    }
                }
            }
        }
    }
}
let Variable = 0
let Melody = ""
let list: string[] = []
pins.A1.setPull(PinPullMode.PullUp)
pins.A2.setPull(PinPullMode.PullUp)
list = []
forever(function () {
    if (!(pins.A1.digitalRead())) {
        music.stopAllSounds()
        music.setVolume(0)
    } else {
        if (!(pins.A2.digitalRead())) {
            for (let index = 0; index <= 8; index++) {
                if (0 <= pins.A3.analogRead() && pins.A3.analogRead() < 100) {
                    ChooseAMelodyKey(Math.randomRange(1, 3))
                } else {
                    if (100 <= pins.A3.analogRead() && pins.A3.analogRead() < 200) {
                        ChooseAMelodyKey(Math.randomRange(2, 4))
                    } else {
                        if (200 <= pins.A3.analogRead() && pins.A3.analogRead() < 300) {
                            ChooseAMelodyKey(Math.randomRange(3, 5))
                        } else {
                            if (300 <= pins.A3.analogRead() && pins.A3.analogRead() < 400) {
                                ChooseAMelodyKey(Math.randomRange(4, 6))
                            } else {
                                if (500 <= pins.A3.analogRead() && pins.A3.analogRead() < 600) {
                                    ChooseAMelodyKey(Math.randomRange(5, 8))
                                } else {
                                    if (600 <= pins.A3.analogRead() && pins.A3.analogRead() < 700) {
                                        ChooseAMelodyKey(Math.randomRange(1, 8))
                                    } else {
                                        if (700 <= pins.A3.analogRead() && pins.A3.analogRead() < 800) {
                                            ChooseAMelodyKey(Math.randomRange(2, 7))
                                        } else {
                                            if (800 <= pins.A3.analogRead() && pins.A3.analogRead() < 900) {
                                                ChooseAMelodyKey(Math.randomRange(3, 6))
                                            } else {
                                                if (800 <= pins.A3.analogRead() && pins.A3.analogRead() < 900) {
                                                    ChooseAMelodyKey(Math.randomRange(Math.randomRange(1, 4), Math.randomRange(5, 8)))
                                                } else {
                                                    ChooseAMelodyKey(Math.randomRange(Math.randomRange(1, 3), Math.randomRange(6, 8)))
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Melody = "" + convertToText(list.shift()) + convertToText(list.shift()) + convertToText(list.shift()) + convertToText(list.shift()) + convertToText(list.shift()) + convertToText(list.shift()) + convertToText(list.shift()) + convertToText(list.shift())
            music.playMelody(Melody, 256)
        } else {
            if (Variable != pins.A3.analogRead()) {
                Variable = pins.A3.analogRead()
                Variable = Variable + 10
                Variable = Math.constrain(Variable, 0, 255)
                music.setVolume(Variable)
            }
        }
    }
})

circuitplayground-MakeIt_Radio Fin.uf2

Makefile
MakeCode File of Project
No preview (download only).

Credits

Jake Vaughan
4 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.