Loading... (0%)

Piano Notes

22 March 2015

IMG_6606

This tutorial will show you one possible way you can use the programmable microcontroller—to visualize music! When triggered the LEDs will light up in order corresponding to the notes of a very basic piano song- “Hot Cross Buns.”

You will need:

  • An In System Programmer (ISP) to connect the microcontroller sticker to the computer and load your code, such as:
    • Tiny AVR programmer this programmer is easiest to start with. It also has a convenient connector for easily programming bare Attiny85 microcontrollers
    • AVRISP MKII this can be used to program any sort of AVR microcontroller
    • Arduino as programmer If you have an Arduino handy, you can also use it as a programmer. To do so, you will first need to program your Arduino board as a programmer. Here are tutorials for turning the Arduino UNO and Arduino Leonardo into ISPs. For the Arduino UNO, you will also need a 10uF or larger capacitor.
  • Microcontroller circuit sticker (in the Sensors add-on)
  • Circuit sticker programming adapter (also included in the Sensors add-on)
  • 6 jumper wires
  • LED stickers
  • Copper foil tape
  • Cardstock
  • 3V coin cell battery
  • Black marker
  • Binder clip

IMG_6611

Step 1. See “Programming the Microcontroller Sticker” to learn how to set up your microcontroller and computer to begin coding.

Screen Shot 2015-03-15 at 11.10.08 PM

Step 2. Plan the circuit you want to create. I first used a separate piece of paper to sketch out the piano keys and where the microcontroller would be placed.

IMG_6574

Step 3. Draw in the locations of the LEDs, copper foil, touch sensor, and battery. The structure of your circuit can be based on that shown in the “Attiny85 Microcontroller Template.”

IMG_6575

Step 4. Once you have your circuit drawn out and know which LEDs correspond to which pins on the microcontroller it is time to begin programming:

  • Give each pin you will be using a name and set “buttonState” to zero.

Screen Shot 2015-03-22 at 6.42.57 PM

  • Initialize pins 1-3 as output and pin 4 (the button) as input.

Screen Shot 2015-03-16 at 1.21.23 AM

  • Set up “if” statement that will run the LED pattern if the button is pressed.
    HINT: If your pin 4 is not connected to anything (which it should not be), then the “digitalRead” command randomly returns either HIGH or LOW. Whichever value it returns is changed once the button is pressed, allowing the “else” function of your “if” statement to be carried out.

Screen Shot 2015-03-16 at 1.22.23 AM

  • Based on the piano music (shown below), program the LEDs to light up in the correct order for the proportionally correct amounts of time
    HINT:  The command “digitalWrite(pin, value)” takes a pin and sends a voltage across it. If the value is “HIGH”, the voltage will be set to 5V and the LED will turn on. If the value is “LOW”, the voltage will be set to 0V (Ground) and the LED will turn off.
    HINT: The command “delay” will delay the next command in the sequence by the input number of milliseconds.
Screen Shot 2015-03-16 at 12.43.13 AM Screen Shot 2015-03-16 at 12.43.42 AM
  • Upload code to the microcontroller

Notes:
– It may be helpful to attach your microcontroller to the Attiny85 Microcontroller Template while you program to ensure all your code is working correctly.
– This program could be made much more concise by using functions (instead of repeating the entire code to turn each LED on and off), but for simplicity, this tutorial does not use this method.

Step 5. Create your final circuit (based on previous sketch) on a piece of card stock.

IMG_6577 IMG_6580 IMG_6583

Step 6. Add LEDs

IMG_6586

Step 7. Once your program has been uploaded to the microcontroller, disconnect the microcontroller from the Attiny85 and add it to your circuit.

IMG_6587

Step 8. Add battery. Secure with binder clip.

IMG_6589

Congrats! Your programmable piano is complete. Simply connect the two pieces copper tape with your finger to play back your notes.

IMG_6606

hot cross buns