Particle Jukebox Project

The Internet of Things

This was my first project getting into something like this and I have to say I really enjoyed the experience. So much so that I'm now starting to collect more IOT devices and fiddle with them during my free time. After spending an entire Saturday learning this, I created this project with the intention to share how to quickly set up and understand how this all works together. Maybe I'm alone in this, but the basic "Hello, World" tutorial to get a light to blink just doesn't cut it. In my opinion, if you really want to understand something it's going to first require an idea of what you want to accomplish and proving to yourself you can do it!

Using Grove Starter Kit for Particle Mesh

Particle Jukebox is a fully functioning demo for The Grove Starter Kit for Particle Mesh which demonstrates how to use Particle.function(). Go ahead and flash ⚡️ this sketch to your Particle Argon and see how it works!

Requirements

  • One already-claimed Particle Argon
  • Grove Starter Kit for Particle Mesh

    • Grove shield for Particle Argon
    • Button ~ plugged into grove shield D2
    • Buzzer ~ plugged into grove shield D4
  • USB Cable & Internet! (duh)

Three Versions of Particle Jukebox

  • "Button Only" version using only the button (See particlejukebox_btnonly.ino)
  • "Cloud Only" version using only Particle.function() (See particlejukebox_cldonly.ino)
  • "Full" version using both the button as well as Particle.function() (See particlejukebox.ino)

Note! You don't have to use these products. You could use a plain Arduino with different sensors and effectors as well. I would recommend using the "Button Only" version.

Tunes

After you have uploaded particlejukebox.ino to your Particle Argon, you will find "PlayTune" located in the Functions section in your console. (It's also handy to control your Particle Argon using the app!) Enter any of the following to listen: Pokémon, Kim Possible, Power Rangers, Sesame Street, Smooth Criminal, Star Wars, Indiana Jones, Mario Bros, Legend of Zelda, Door Knock

Also, this is the play order each time the button is pressed. When you finally hear the "Door Knock" melody, it will reset to the first tune. If you ever mistype when calling the Particle Function, the "Door Knock" melody will also play for you.

Composition Using Equal Temperament

melody requires an arrangement of notes. For regular notes you will need to write in lowercase (a) and sharp notes in uppercase (A). Keep in mind B (B#) and E (E#) are both invalid.

Code Note 440Hz x 4
0 Pause 0
a A 1760
A A# 1864.66
b B 1975.54
B NA INVALID
c C 2093
C C# 2217.46
d D 2349.32
D D# 2489.02
e E 2637.02
E NA INVALID
f F 2793.82
F F# 2959.96
g G 3135.96
G G# 3322.44

The jukebox() function requires the melody array melody[], the melody sequence melodySeq[] and the length of the arrays. The key to getting your tune working correctly is to make sure melody[] & melodySeq[] are equal in length and specifying this length when calling jukebox().

int jukebox(int melody [], int melodySeq [], int length) {
    for (int note = 0; note < length; note++) {
      int duration = 1000/melodySeq[note];
      tone(BZZ, melody[note], duration);
      delay(duration * 1.30);
    }
    tune++; // next tune
}

Tune Example: Pokémon

To compose a tune you will need to write the melody in one array, the rhythm in another array, and both arrays to be equal in length.

// "PO - KE - MON!"
int pokemon[] =    {d,f,g}; // the melody
int pokemonSeq[] = {8,8,8}; // the rhythm
// calling the simplest tune in the list
jukebox(pokemon, pokemonSeq, 3); // length of this is 3!

Different Examples Shown

However, in some cases you might need one note at a higher or lower octave. Just write whatever note with *2 or /2

// (with a# one octave above)
int indianaJones[] = {d,D,f,A*2,d,f,D};

melodySeq is used to create the rhythm to your melody. It can be a little tricky, but the numbers given to the array should make sense for someone familiar to playing an instrument. There are whole 1, quarter 4, eighth 8 etc. You will see a few variances in this sketch such as 6, 12, and 3. This was intended to slow down the melody without altering the loop. Smooth Criminal is an example of this. (You can also play around with different time signatures, if you know what you're doing!)

You can also add pauses to your tune by adding 0.

int mario[] =    {e,e,e,d,e,g,0,g/2};
int marioSeq[] = {8,8,4,8,4,4,4,  4};

Additional Notes

This was written with the button connected. Once the button has been removed, you will immediately hear every tune play in a continuous loop. I highly recommend commenting out the following if you wish to control your Particle Argon using only the Particle Cloud Function:

  • #define BTN D2 at the top
  • pinMode(BTN, INPUT); in your void setup()
  • Everything inside void loop()

Originally I had the the function to get the length without counting, but ran into strange behavior ~ best to count. (I'm learning c++ as I go :) As a suggestion, if you wish to compose a full song, I would segment them such as "Chorus" and "Verse" and have the jukebox call each of them individually. Just don't annoy your friends or neighbors.

Copyright © 2020. Jake Birkes