Santiago Vega
Published

DIG 3602 Project 1: Megalovania Coded

Using a processor, some code and electrical tape, we can bring Sans from Undertale to life. You're gonna have a bad time...

BeginnerShowcase (no instructions)3 hours380
DIG 3602 Project 1: Megalovania Coded

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
Alligator Clips
Alligator Clips
×1
Rechargeable Battery, Lithium Ion
Rechargeable Battery, Lithium Ion
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Big Red Dome Button
SparkFun Big Red Dome Button
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Hand tools and fabrication machines

Tape, Electrical
Tape, Electrical
Scissor, Electrician
Scissor, Electrician
aerosol glue
card board

Story

Read more

Schematics

Circuit Board connected

After installing my Javascript code to my circuit board, I connected alligator clip cables to the proper pins as well as to the red button in order to test it and see if the button works properly.

Code

Megalovania Button

JavaScript
This is the Javascript code I used through MakeCode in order to make the processor respond to an external switch (in this case a big, red button) to both light up in a particular light pattern and play the first four chords of Megalovania (the boss battle theme song for Sans in the video game Undertale) for 6 seconds whenever it is pressed. Before the button is pressed, the processor will always stay showing blue light. After the button is pressed and six seconds have passed, the processor will stop its light animation and revert back to its quiet, blue mode. In order for the button to be pressed and registered, I had to set it so that pull pin A2 was down on start.
pins.A2.setPull(PinPullMode.PullDown)
forever(function () {
    if (pins.A2.digitalRead()) {
        music.setVolume(255)
        music.playTone(294, music.beat(BeatFraction.Quarter))
        music.playTone(294, music.beat(BeatFraction.Quarter))
        music.playTone(587, music.beat(BeatFraction.Quarter))
        music.playTone(440, music.beat(BeatFraction.Half))
        music.playTone(415, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Half))
        music.playTone(294, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        music.rest(music.beat(BeatFraction.Eighth))
        music.playTone(277, music.beat(BeatFraction.Quarter))
        music.playTone(277, music.beat(BeatFraction.Quarter))
        music.playTone(587, music.beat(BeatFraction.Quarter))
        music.playTone(440, music.beat(BeatFraction.Half))
        music.playTone(415, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Half))
        music.playTone(294, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        music.rest(music.beat(BeatFraction.Eighth))
        music.playTone(262, music.beat(BeatFraction.Quarter))
        music.playTone(262, music.beat(BeatFraction.Quarter))
        music.playTone(587, music.beat(BeatFraction.Quarter))
        music.playTone(440, music.beat(BeatFraction.Half))
        music.playTone(415, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Half))
        music.playTone(294, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        music.rest(music.beat(BeatFraction.Eighth))
        music.playTone(247, music.beat(BeatFraction.Quarter))
        music.playTone(247, music.beat(BeatFraction.Quarter))
        music.playTone(587, music.beat(BeatFraction.Quarter))
        music.playTone(440, music.beat(BeatFraction.Half))
        music.playTone(415, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Half))
        music.playTone(294, music.beat(BeatFraction.Quarter))
        music.playTone(349, music.beat(BeatFraction.Quarter))
        music.playTone(392, music.beat(BeatFraction.Quarter))
        light.clear()
    }
})
forever(function () {
    while (input.buttonA.isPressed()) {

    }
})
forever(function () {
    if (pins.A2.digitalRead()) {
        light.showAnimation(light.cometAnimation, 6000)
    } else {
        light.setAll(0x007fff)
    }
})

Credits

Santiago Vega

Santiago Vega

4 projects • 0 followers

Comments