How many times have you heard a song - on the radio, during a movie, or at a concert - and thought "Man I wish I could play that"? Now you can! This project allows you to learn a song note by note on the piano by lighting up appropriate LED lights that correspond to each individual key on the piano. In fact, even if you don't have a piano but have a smaller electronic keyboard, you can customize it for that. Some electronic keyboards actually have light-up keys for just this purpose, but doing it on a real piano is so much more satisfying. Have fun, and learn some songs!
The three main components of this project (like many) are:
2) Hardware (non-electronic)
3) Electronics and Wiring
Although they're separate parts of the project, in reality you'll frequently be working on more than one at a time simply because how you decide to do one part affects how you'll do another. A good thing about doing them in parallel, however, is that you keep the big picture in mind and if you get tired of writing code, you can design your acrylic parts, and if you're tired of the computer altogether you can wire up some resistors and LEDs and have some fun with that. The parts are in a specific order in the Instructable, but how you do it is up to you.
The biggest question when I started out was "How the heck do you individually control 88 LEDs?!?!" Fortunately, after some research I found some chips designed to do just that and some Arduino tutorials and code that helped along the way. Aside from that question, everything else was fairly straightforward or at least only required me to pick from several options - what to make the strip out of, how to hold the LEDs in place, how to write the code to make it all run, and so forth. Let's talk about the big question in a little more depth so you have an idea of how it all works before you get started.
The chips I got are LED matrix (or 7 segment display) drivers, which means that as far as the chip is concerned, we have our LEDs wired as if they're in a square grid, with a certain number of rows and columns - the positive terminals are common in each column, and the negative terminals are common in each row. This allows 64 LEDs (in an 8x8 grid) to be controlled by each chip and only requires three (that's right THREE!!!) control inputs. No matter which or how many of the LEDs you want to turn on, the system can handle it.
But wait, if you want to turn on LEDs (1,1) and (2,2), wouldn't that also light up (1,2) and (2,1), because in order to achieve the original goal all of rows 1-2 and columns 1-2 would have to be on? This is where the clock inside the chip comes in - the LEDs aren't actually on continuously. Rather, they're blinking so fast that the human eye observes them as continuously on. This is how unwanted LEDs can remain off!
So although we see the strip as just a line of LEDs, they're wired as if they're in two square matrices - one 8x8 (first chip) and one 5x5 (second chip), which adds up to 89 keys (the final "row" of the 5x5 matrix only has 4 LEDs, so that brings us down to 88). Voila!
How do we tell the chip which LEDs to illuminate? That's all done using binary numbers. Using some code borrowed from developers online (see the code for the attribution), I created the program in such a way that all you have to do when translating a song is to call the command playKey(...). This plays the given numbered key, starting with 1 on the left and ending with 88 on the right. This command takes the key number and translates it so the chips can do their duty by doing the following: the key number is translated into a row and column number, which is then translated into a row number and a binary number that represents which LED should be on (read from the left, not the right). For example, if I call playKey(13), which is A, the functions translate that as row 2, column 5; then since 2^5 is 32, that would be the number that goes to the chip. Reading from the left, 32 is 00000100, which represents the state of the second row. The same concept applies when we're dealing with lighting up multiple LEDs - it's all about binary numbers! Check out the code for the exact functions and a little more explanation.
Finally, there's a potentiometer attached to it all to control tempo - something really, really important when you have no idea what you're doing...
NOTE: This was not an easy Instructable to write because of how complicated it was to put everything together and make it all work. Don't hesitate to let me know if something is confusing or unclear, or if you have specific questions!
Let's get going!