2019 November 16

Particle Jukebox


This was my very first project getting into IOT and I really enjoyed the experience. So much so that I'm now starting to collect more IOT devices and fiddle with them on 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.

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

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 an 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 and sharp notes in uppercase. Keep in mind B (B#) and E (E#) are both invalid.

CodeNote440Hz x 4
0Pause0
aA1760
AA#1864.66
bB1975.54
BNAINVALID
cC2093
CC#2217.46
dD2349.32
DD#2489.02
eE2637.02
ENAINVALID
fF2793.82
FF#2959.96
gG3135.96
GG#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().

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.

More Examples

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

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 including 0.

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:

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

Originally I had the the function to get the length without counting, but ran into strange behavior ~ best to count. 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 © 2021. Jake Wantulok