As many of you know the Legend of Zelda is one of the most popular video game series to have ever been made. The Ocarina of Time is probably the most popular game in the series having a total of 7.6 million copies sold during it's lifetime. One of the most iconic features of the Ocarina of Time is when you open a chest.
As you go to open a mysterious chest a tune starts to play. This tune causes anticipation and suspense. When the tune hits it's climax Link holds the item he has found over his head in victory and a triumphant score is played. You feel accomplished for just opening a chest and holding an item.
So the goal for to day is to recreate that here. So equip Master Sword and grab you Hylian Shield, you have some items to collect!
- A chest or a box or a container of some sort
- I bought a plain chest from a craft store and then stained the wood
- copper tape
- a piezoelectric speaker
- WS2812 LED strip (length can vary)
- chipKIT Max32
- 4-AA battery pack
- AA batteries
- 10K-Ohm Resistors
- (Optional) A lever or switch
Once you have clear all of the dungeons and gathered all of your items let the adventure begin!
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: The Design Dungeon
The first thing to consider when setting up your chest is the circuit of everything inside. The main part you really need to worry about is the button set up. The reason why this is such a big concern is because I used the actual chest as a button. When the lid is closed the button is being pressed. When the lid is open the button is not being pressed. It's a great way to get the timing correct for when the user opens the box.
You'll want to make sure you have enough space in your chest to hold a battery pack, a Max32, a LED strip, and wires. If you want to have your box look more beautiful then you'll have to find away to cover up all the wires and circuitry.
Step 2: The Music Dungeon
To create the classic song from Legend of Zelda you'll need to know the notes, have sheet music or be able to remember how it goes exactly. I found some sheet music at this website.
To create the notes you need you'll need to know the frequencies of each note. Since most people don't have super precise hear and frequency calculating ears you can use this helpful wiki page.
Finally to defeat the Music Boss you'll need to make a function in Mpide that will take the frequencies and make them play over the piezoelectric speaker. There's a handy learn module on the Digilent website that can help with this or you can check out my previous Instructable or this blog post.
Here's some handy pointers when you're coding though:
- Define all of your notes and variables and have them set to the correct frequencies. This will make things much easier.
- You'll need to know the tempo of the song.
- Having a little bit of a musical back ground would be helpful
I'll post how I coded this section later in this Walkthrough but I encourage you to take a shot at it yourself.
Step 3: The Dungeon of LEDs
I used a WS2812 LED strip from Digilent. The length of the strip should wrap around the inside of your container. I had a total of 12 LEDs on the strip. If you purchase the strip from Digilent you won't need to solder any wires to the strip. If you plan on modifying the strip or using a strip that doesn't have the preset wires you may need to solder some stuff to it. Make sure when you solder that you have the strip facing the correct way. solder the wires on the side where the arrow is point towards the other end. Check out this Instructable to see how to use the WS2812 LED strip.
You will need to download the PIXcel library to get the LEDs to work properly. If you follow the Instructable above it will show you how to download and install the library easily. If you already know how to install Libraries you can click here to get to the repository of the PIXcel library for the WS2812 on the chipKIT.
The way I wanted my LEDs to work was I wanted to have a trailing effect with a Gold light LED. The LED would be full bright and then the next LED would less bright and so on and so on. I was able to talk to one of my coworkers and friend, Marshall, who generously let me use his one of his old projects. Marshall's LED Fedora is quite popular around the office. There is one effect that it can do where it trails green all the way around the hat. You find his LED project on his github. I'll describe how to use the code later on.
You can use either green-red-blue(GRB) or hue-saturation-value(HSV) values for your LEDs. The GRB is better for getting more precise colors but the HSV is either to change brightness saturation. I used the HSV to get my gold colors.
Value: varied to change brightness.
Step 4: The Chest in the Dungeon
To set up your chest you'll need to start with some copper tape. The way to get this to work is that there needs to be a button being pressed so the chipKIT knows to not play music and start the lights right away. The chest I'm using isn't heavy enough to hold down an actual push button. I improvised and made a quick button using the chest it's self.
To start take a piece of the copper tape and put on the middle part of the back edge of the lid . Next you'll want to take two other pieces of copper tape and put them on the connecting edge of the chest where the lid copper tape will touch them. Make sure those two pieces aren't touching. As you can see when you close the lid it will create a closed circuit. When it's open the circuit is broken.
Next you'll need more copper tape and wires. Take one wire and put it on one of the bottom copper strips and the lay the new copper strip over it to hold it in place. On the other side put two other wires on the same way. The single wire will be the power to the button. The other wires will act as the ground and the wire signal. The ground and signal will need the 10k-Ohm resistors for this.
Step 5: The Mpide Dungeon With the Coding Boss
To start with your code you will need to include your PICxel.h library
I also defined the pins that I used for the button, piezoelectric speaker and the LED strip. You will also need to define the number of LEDs on your strip.
to get the LED strip working you'll need to define the strip function. here you will be to decide if you want to use either GRB or HSV.
PICxel strip(number_of_LEDs, LED_pin, HSV);
From there I defined all of my global variables such as my notes and the LED values.
The next set is part of Marshall's code where he defines the hue, saturation and value variables. He also sets up an array for the values for each LED strip. I modified his array to fit the length of my strip, the result I wanted, and the colors and values I needed.
The setup function is next where you set the piezo pin to output and the button to input. Also you need to intialize your LED strip to make it begin.
You need to make a function that will play the your notes frequency. earlier I linked you to some websites that should help with this. Try to figure this out yourself if you can but I will post my code for this also.
Next I made my functions for the trailing LED effect and then all LEDs on. The trailing LEDs came from Marshall's code but it was modified. The full effect was simple to create. Give it a shot.
My music playing function is more then just for music. I started this program without considering doing some form of interrupts. So after each note I had the LED trail increment once. At the beginning you'll want to define each of your note lengths based on your tempo. Take the tempo (beats per minute) and convert it to milliseconds per beat. So a sixteenth note is 1/4 of tempo calculated.
The loop function is where your code will determine if the box is open or not. I used a couple if statements for each section. So if the button is high (lid is closed) nothing happens. If the button is low (box is open) music plays and lights go. Try to give it a shot before you us my code.
Step 6: Final Boss (Finishing Touches)
Once everything is set up and working you can do the final steps. Any of these steps are optional and they are purely suggestions.
If you want you add an On and Off switch to your power source. That way you don't have to fiddle with wires every time you want to turn it on. You could also even cut a hole into your box to put the switch on the outside of the box.
Make it pretty! Add some designs if you want to it. Spruce up the outside so it looks rustic or old or how ever you want.
Try hiding the circuitry on the inside. You could get a piece of wood to cover up the board and the wires but still have the LEDs out. You could stick the batteries in the lid of box so it's out of the way.
Try thinking of other ways to make your box stand out. Remember, the cooler the box looks the better the treasure will be inside.
Step 7: Final Thoughts
I hope you guys have fun making this as much as I did. I would suggest you try writing the code yourself before trying others. It's always good to have some practice. If you need any tutorials check out the chipKIT website or the Digilent Learn Webpage.
If you have any feedback at all please let me know! I'd love to see what you guys do with this or how you improve it. Let me know if there's anything wrong with this Instructable or the project itself. I'll try to fix it as quickly as possible. Thank You and enjoy.
Keep on building!
Some of these photos were taken by my friend Quinn Sullivan.
Participated in the