This sort of works as an LP player. The difference is that instead of using a needle on a plastic disc, we use three IR sensors in a row to read a pattern from a paper disc. If you are both musically and digitally inclined, you will have lots of fun creating melodies with this.
Materials
- 1 Arduino Uno board
- 1 Basic Education shield
- 1 Piezo
- 1 IRArray
- 2 black jumper wires
- 5 colored jumper wires
- Binary LP kit
- Binary LP paper disc
Instructions
Code
You can find the code in File -> Examples -> BasicEducationShield-> Magic -> BinaryLP
How it works
The three IR sensors in the IRArray can detect black or white from the paper disc. This means that we can detect 8 different combinations of black and white. Do you remember how to count in binary? That will come in handy right now. In the program we use the command readBinary()
to read from the disc and receive a value from 1 to 7. If the pattern is white, white, black, we receive a ’1′. If the pattern is white, black, white, we receive a ’2′ etc. We then use the read value to play a note. You decide what note to play for each number in the function playNote()
. E.g. if we receive a ’1′ we play NOTE_C4
and if we receive ’2′ we play NOTE_D4
. In this example we are using the tones from the scale C major. Check the tab “pitches.h” to see what other tones you can use. If we read a ’0′ we don’t play a specific note, instead we let the white space decide how long the last note is played The longer the white space, the longer the note. If the last note we played is the same as the current, we let the piezo be quite for 20 milliseconds so that we can distinguish 2 different notes.
Troubleshooting
- Refer to the illustration and double check your connections. Make sure the shield and wires are firmly connected.
- Debug the IRArray, see the IRArray reference.
Experiment further
- Compose a few different melodies.
- Come up with new way to use the binary readings.