I typically see piano tutorial movies on YouTube the place lights seem to light up the gamers’ arms proper as they play the keys. Utilizing the facility of a MIDI, a Raspberry Pi, and a few programmable LEDs, I wished to see if I might flip my piano into one thing comparable. Should you dabble in know-how as a lot as you do music - right here’s methods to construct a LED strip in your piano that lights up as you play it.
What You’ll Want For This Challenge
- Raspberry Pi 4 or Raspberry Pi 3, or Raspberry Pi Zero with energy adapter and SD card
- Digital Piano with MIDI USB output and corresponding USB cable
- Programmable LED strip (1 meter or better)
- Jumper cables
The right way to Flip a Raspberry Pi right into a Piano LED Mild Up Strip
Earlier than you get began, get your Raspberry Pi arrange. Should you haven’t achieved this earlier than, see our article on methods to set up a Raspberry Pi for the primary time or methods to do a headless Raspberry Pi install (with out the keyboard and display screen). For this mission, we suggest a headless Raspberry Pi install.
1. Set up git. We’ll want it to obtain the code from GitHub.
sudo apt-get replace sudo apt-get -y set up git
2. Clone the repository to your own home listing. This can guarantee we have now all of the code and audio information we have to run the mission.
cd ~/ git clone https://github.com/rydercalmdown/piano_key_illuminator.git
3. Run the “make set up” command to put in all mission dependencies. This script will deal with putting in decrease degree dependencies, in addition to the Python libraries you want for the mission to run. This could take about 10-Quarter-hour on a Raspberry Pi 4.
cd ~/piano_key_illuminator/ make set up
4. Unbox your LED strip and affix it to the piano with the sticky tape on the again. If it’s not lengthy sufficient to cowl your complete size of the keys, place it in the midst of the piano.
5. Connect the 5V and floor pins of your LED strip to your Raspberry Pi board pins 4 and 6 respectively.
6. Connect the data-in pin of your LED strip to your Raspberry Pi board pin 12.
7. Utilizing a USB cable, connect the MIDI out of your piano to your Raspberry Pi (any USB port).
8. Flip the piano on and make sure it's listed with the next command. You need to see the title of your instrument.
9. Set the self.lc.led_count variable within the src/app.py file to the variety of LEDs in your strip (default 60).
nano src/app.py # self.lc.led_count = 60
10. Use the next command to begin the appliance on the Raspberry Pi. If profitable, the LEDs will flash a couple of occasions earlier than the appliance begins. When a key's depressed, the corresponding LED will illuminate, and the console will present the ID of that key.
INFO:root:41 - note_on INFO:root:41 - note_off
11. Press the bottom key in your piano lined by the LED strip, then the very best. Word the quantity/id of those keys within the console output and set the next variables in app.py:
INFO:root:30 - note_on INFO:root:30 - note_off INFO:root:101 - note_on INFO:root:101 - note_off
self.lc.highest_key = 101 self.lc.lowest_key = 30
12. Run this system as earlier than. With the adjusted settings, it would now approximate which LED to light up primarily based on which key's pressed. That is achieved because of totally different LED strips having totally different spacing, or not having sufficient to cowl your complete board.