The example code is easy to modify to make your own custom mini-tunes.
Change the Tempo
In the example code, recall that a set variable block initialized beat to 500. Later, beat is inserted in to the the frequency out block's duration field.
This makes each note last for 500 ms, giving you a little time to tilt the board to a new position to select a new note before the code makes another trip through the repeat forever loop. If you want to slow down the tempo, perhaps to practice the movements to play a tune, initialize beat to 750 or 1000. For peppier tunes — and a coordination challenge — try reducing beat to 250.
- Experiment with different beat intialization values.
Play New Notes
If you want to play different notes to make your own 4-note tunes, simply replace the four elements in the Note array with new frequencies.
To make it easier to see which tilt motion will correspond to which frequency (and which LED will light up) you can insert this debugging code into your program, just below the index = get the states...blocks.
Here's what the Terminal would show if you tilt your Board downward to the right.
The familiar song Mary Had a Little Lamb uses only four notes: A, B, D, and G. It also has a simple, steady beat which works well for our Tilt Tunes toy.
B A G A B B B A A A B D D ma-ry had a lit-tle lamb, lit-tle lamb, lit-tle lamb, B A G A B B B B A A B A G ma-ry had a lit-tle lamb, its fleece was white as snow
- Referring to the keyboard diagram below, try modifying your program to use these four notes, then see if you can play the song.