Using the Circuit Playground to make lights and sounds when shaken is pretty straightforward. If this is your first Circuit Playground project, you'll first need to make sure you've installed the Arduino IDE, added the Circuit Playground library to the Arduino software, and and been through the basic tutorials on its use. This excellent guide, Introducing Circuit Playground and Circuit Playground lesson #0 will show you how to do all of that and get you going.

Plug your Circuit Playground into your computer now, and launch the Arduino IDE. Double check that you've selected the board and port as in the Lesson #0 tutorial and are ready to upload code.

The Arduino sketch Circuit Playground Make Believe sketch does the following:

  • Plays one light pattern and sound file while the Circuit Playground (and the prop weapon to which it has been affixed) is idle
  • Plays a second light pattern and sounds file when swung
  • Plays a third light pattern and sound file when tapped


Download the file below, then unzip it and place it in your Arduino sketch directory.

Open the CircuitPlaygroundMakeBelieve sketch in Arduino, you'll notice that there are also three other tabs that open -- knight.h, laser.h, and wand.h. These are three different theme sets, which are combinations of light animations and sound files that are triggered at different motion thresholds on the Circuit Playground's accelerometer.

Upload the sketch to your Circuit Playground and then try it out. The NeoPixels will play their idle animation and you'll hear the idle sound coming from the piezo speaker.

Swing the Circuit Playground around a bit to trigger the swing animation and sounds. This works because the code is checking the built-in accelerometer for sudden changes above a certain threshold. When the change is great enough, the swing is triggered.  

The code also checks for even larger changes in acceleration, which indicates that there has been a tap on the Circuit Playground, or that your prop foam sword has hit its target! In this case, it will play the tap animation and sound.

The sketch uses pre-made theme sets of effects for use with different props. You can try them out to see which one works best for you. 

If you look at the top of the Arduino sketch you'll see the theme choices. By uncommenting one (and commenting out the other -- there can only be one uncommented at a time) that theme set of lights and sounds will be used the next time you upload the sketch to your Circuit Playground. 

For example:

// Enable ONE of these lines to select a theme:
//#include "knight.h" // Swoosh & clank metal sword
#include "laser.h"  // MWAAAW! "laser" sword
//#include "wand.h"   // Magic wand

will use the laser.h theme set. To switch to the wand.h theme set, do this:

// Enable ONE of these lines to select a theme:
//#include "knight.h" // Swoosh & clank metal sword
//#include "laser.h"  // MWAAAW! "laser" sword
#include "wand.h"   // Magic wand

This guide was first published on Oct 26, 2016. It was last updated on Oct 26, 2016.

This page (Prep the Circuit Playground) was last updated on Oct 23, 2016.

Text editor powered by tinymce.