Sword & Wand Prop Effects with Circuit Playground

Similar documents
NeoPixie Dust Bag with Circuit Playground Express

Circuit Playground Express Laser Tag

Wind Blowing Emoji Prop

Bunny Ears with MakeCode

Adabot Operation Game

Crickit Carnival Bumper Bot

Slider Crank Mechanism -- from Cardboard and Craft Sticks

Steven Universe Cosplay Shirt & Gem Created by Erin St Blaine. Last updated on :54:25 PM UTC

Snake Charmer Box. Created by Dano Wall. Last updated on :07:25 PM UTC

Crawling Baby Sea Turtle Robot

Pushrod Garage. Created by John Park. Last updated on :07:30 PM UTC

Crawling Animatronic Hand

Portable Apple Watch Charger

Ping Pong Ball Launcher

Con Badge with Circuit Playground Express

Infinity Mirror Valentine's Candy Box

Hammer Time Mini Golf Hazard with Crickit

Easy Sparkle Pocket T-Shirt

Crickit Dancing Marionette Kit Created by Dano Wall. Last updated on :03:11 PM UTC

Feather Weather Lamp. Created by Ruiz Brothers. Last updated on :54:26 PM UTC

UFO Flying Saucer with Circuit Playground Express

NeoMatrix 8x8 Word Clock

Neon LED Signs. Created by John Park. Last updated on :11:09 PM UTC

Paper Airplane Launcher

Circuit Playground Combadge

Crickit Powered Holiday Diorama

NeoPixel Fairy Crown. Created by Erin St Blaine. Last updated on :22:47 AM UTC

Android GBoard Morse Code Control with Circuit Playground Express

Secret Hollow Book Intrusion Detector

FLORA TV-B-Gone. Created by Becky Stern. Last updated on :32:57 PM UTC

PyPortal NeoPixel Color Picker Created by Kattni Rembor. Last updated on :42:41 PM UTC

Circuit Playground Digital Input

3D Printed Case for Adafruit Feather

Solar Boost Bag. Created by Becky Stern. Last updated on :44:55 PM UTC

CPX Mystery Dreidel. Created by Kathy Ceceri. Last updated on :51:40 PM UTC

CircuitPython Snow Globe

Milk Jug Glow Skull. Created by John Park. Last updated on :28:36 PM UTC

Mini Golf Course with Circuit Playground and Crickit

Trellis 3D Printed Enclosure

Circuit Playground Yoyo

NeoPixel Bike Light. Created by Ruiz Brothers. Last updated on :43:46 PM UTC

'Sup Brows. Created by Kate Hartman. Last updated on :52:04 PM UTC

Guardian Shield+ Zelda Breath of the Wild

i2c/spi LCD Backpack Created by lady ada Last updated on :11:04 PM UTC

Clockwork Goggles. Created by John Park. Last updated on :03:10 PM UTC

Overwatch Prop Gun: Lucio's Blaster Pt. 3

Glowing Smokey Skull. Created by Ruiz Brothers. Last updated on :03:40 PM UTC

GPS Logging Dog Harness

Reindeer Mask with Animated Eyes

LED Eyes. Created by Ruiz Brothers. Last updated on :50:55 AM UTC

Sewable NeoPixels. Created by Becky Stern. Last updated on :50:14 PM EDT

Crickit Powered Mini Chair Swing Ride!

Bluetooth Controlled NeoPixel Headphones

3D Printed Google AIY Voice Kit

FLORA and GEMMA ICSP. Created by Becky Stern. Last updated on :42:16 PM UTC

Trinket NeoPixel LED Longboard

Audio Prank Gift Box. Created by Becky Stern. Last updated on :46:15 PM UTC

Light-Up Angler Fish Embroidery

Bike Wheel POV Display

Stumble-Bot. Created by Dano Wall. Last updated on :04:06 AM UTC

Adafruit Mini TFT " 160x80

Zelda Thunder Helm. Created by Ruiz Brothers. Last updated on :46:52 PM UTC

Coffee Detonator: The TNT Plunger Grinder

Adafruit LED Sequins. Created by Becky Stern. Last updated on :02:00 AM UTC

BLE Light Switch with Feather nrf52840 and Crickit

Simple LED Unicorn Horn

ISS Pin. Created by Leslie Birch. Last updated on :27:30 PM UTC

Celebration Spectacles

Interior Purse Light. Created by Becky Stern. Last updated on :41:08 PM UTC

Tent Lantern. Created by Timothy Reese. Last updated on :17:25 AM UTC

Introducing Circuit Playground

NeoPixel Ring Bangle Bracelet

Chirping Plush Owl Toy

3D Printed Camera LED Ring

Adafruit GPS Hat in Windows IoT Core

Getting Started with FLORA

3D Printed LED Goggles

FLORA and GEMMA ICSP. Created by Becky Stern. Last updated on :30:55 PM EST

Lie Ren's Stormflower Gun Blade

Adafruit TPL5110 Power Timer Breakout

3D Printed 20w Amplifier Box

Getting Started with FLORA

Raspberry Pi Selfie Bot

7" Portable HDMI Monitor

Mad Science Test Tube Rack

NeoPixel Basketball Hoop

PyPortal View Master Created by Ruiz Brothers. Last updated on :51:28 AM UTC

MiniPOV4 - DIY Full-Color Persistence of Vision & Light-Painting Kit

NeoPixel LED Cortana Costume

Adafruit LED Sequins. Created by Becky Stern. Last updated on :00:06 PM EST

Datalogging Hat with FLORA BLE

Adafruit VL53L0X Time of Flight Micro-LIDAR Distance Sensor Breakout

Magical Mistletoe. Created by Leslie Birch. Last updated on :45:29 PM UTC

7 Portable Multitouch Raspberry Pi Tablet

Sino:bit with Arduino

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Mini Mac Pi. Created by Ruiz Brothers. Last updated on :43:27 PM UTC

Mystical LED Halloween Hood

Mystery Box: NeoMatrix Mk I

0.96" mini Color OLED

Transcription:

Sword & Wand Prop Effects with Circuit Playground Created by John Park Last updated on 2018-01-13 05:32:54 AM UTC

Guide Contents Guide Contents Overview Circuit Playground Express with MakeCode Lots of Coding Options Wand Lights and Sound Rainbow Test User Input Setup Alternate Input Shake It Picking Themes Slide Switch Input Variables Conditionals Sound Code Cleanup Prep the Circuit Playground Upgrade a Prop Sword 3D Printed Magic Wand 2 3 6 6 7 8 10 13 15 18 20 21 22 24 30 33 39 41 50 Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 2 of 61

Overview Want to upgrade your prop sword/battle axe/light saber/magic wand with motion reactive light animation and sound effects? You can do just that with this simple project! All you'll need is a Circuit Playground or Circuit Playground Express, a battery pack, and zip ties to attach it all to any prop or toy. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 3 of 61

Or, you can go a bit further and fabricate your own wand with embedded Circuit Playground from scratch using a 3D printer. This more advanced build will require a LiPoly battery and JST switch cable, plus a LiPoly charger, and the use of a 3D printer. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 4 of 61

To program the lights and sounds, there are a couple of options. You'll learn to program the Circuit Playground Express using Microsoft Make:Code's drag-and-drop web interface. Then, you'll program either the Circuit Playground Express or Circuit Playground with the Arduino IDE. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 5 of 61

Circuit Playground Express with MakeCode Lots of Coding Options There are many options for programming the Circuit Playground Express! You can hand-code it with the traditional, text-based Arduino IDE, you can try your hand at the exciting new CircuitPython methods, or you can harness the incredibly user-friendly, yet powerful block-based interface of Microsoft's MakeCode web app!! (You can even go full circle and hand type code inside the MakeCode interface with Javascript!) By simply dragging and dropping elemental code blocks, you can create Circuit Playground Express software in no time, and even test it out with the virtual Circuit Playground Express simulator built into the page. Be sure you've gone through the tutorial here on the basics of MakeCode for Circuit Playground Express. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 6 of 61

Wand Lights and Sound You're now ready to begin coding your own program with the MakeCode interface to use thecircuit Playground Express as a magic wand prop. Click the Projects button so you can start a new project. Click the New Project... button to create the new empty project. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 7 of 61

The new project should have only a single block in the layout area, the forever block. Any block of code you place inside the forever block will run over and over and over and over and over and over and over again. FOREVER! (Unless you create other inputs in your code that can change that, later.) Rainbow Test Try it out now. Click the LIGHT category. A collection of new blocks appears, all related to lighting up LEDs. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 8 of 61

Click the block called show frame of _rainbow_ animation then drag and drop it inside the forever loop. The animation block will snap inside the forever loop, and then after a moment, the Circuit Playground Express simulator will begin to play the rainbow animation. In case the simulator doesn't play, click the play/stop button. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 9 of 61

Notice what is happening here -- even though the show frame of _rainbow_ animation block only tells the Circuit Playground Express to play one frame, since it is inside the forever loop, it plays back a full animation over and over again. Give your file a name in the name field, such as cpe_wand. As you did before, you'll Download the UF2 file, put Circuit Playground Express into bootloader mode by clicking the reset button, and then drag the UF2 file onto the CPLAYBOOT drive. Now, the rainbow animation plays on your Circuit Playground Express! User Input What would happen if you required user input to initiate the show frame of _rainbow_ animation code? Let's find out! Click the INPUT category, then pick the on _button A click_ block. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 10 of 61

This adds the new input block to your layout. Drag and drop the show frame of _rainbow_ animation block out of the forever block and into the on _button A click_ block. Try this out on the simulator by clicking the left button a few times. Each time you do so, the rainbow animation progresses by one frame. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 11 of 61

Download the UF2 file, put your Circuit Playground Express into booloader mode, and drag UF2 file to the CPLAYBOOT drive. Then, click the left button on your real world Circuit Playground Express to see the rainbow animation play back frameby-frame! NeoPixel LEDs can go from very dim to super bonkers bright! You can control them with a range of 0-256 levels of brightness. Adjust the overall brightness of all of the NeoPixels with the set brightness block. Click on the LIGHT category, then pick the set brightness block to add it to your layout area. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 12 of 61

Setup Notice how the new block is greyed out. This means that it isn't currently enabled. It needs to be part of a process that can run during some part of the program. Right now, this can either be any code blocks in the forever loop or any code blocks in the on _button A click_ loop. Neither of these is what we want in the case of setting overall NeoPixel brightness. Sorry guys! For this, we'll use an on start loop. Any code blocks inside of on start will only be run once when the Circuit Playground Express first starts up. Think of it like an initialization phase. Click on the LOOPS category, then chose the on start loop. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 13 of 61

Rearrange the on start loop to the top of the layout graph, just to keep things logically and spatially organized. Then, drag the set brightness block into the on start loop. Try adjusting the brightness value by typing 140 into the set brightness number value block. Then, upload the UF2 file to your Circuit Playground Express. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 14 of 61

When you press the left button the frame of animation will display as before, only this time it'll be much brighter! Alternate Input You can make your Circuit Playground Express do something while it waits to get instructions to do something else. What if we want to have the rainbow animation running unless the button is pressed, and then it'll play a sparkle animation for a moment? You can do this by moving the show frame of _rainbow_ animation block into the forever loop, and then putting some new blocks into the on _buttona click_ loop. First, move the show frame of _rainbow_ animation block into the forever loop. If the LEDs are too bright, you can lower the set brightness value to something like 40 as seen here Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 15 of 61

Duplicate the show frame of _rainbow_ animation block by right-clicking on it and choosing the duplicate dropdown menu item. Then, drag the new block into the on _buttona click_ loop. Change the animation pattern by clicking on _rainbow_ and selecting sparkle instead. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 16 of 61

Try uploading this UF2 code to your Circuit Playground Express. Notice that the rainbow animation plays constantly, until you press the left button. Then, there is a momentary flash as a single frame of the sparkle animation plays. It then returns to playing the rainbow animation, since that's in the forever loop. Well, that's not very fun! Let's use a different kind of loop to play a bit more of the sparkle animation upon each button press. From the LOOPS category, create a repeat _4_ times/do loop. This is a really useful loop that will execute any contained code blocks x many times, with x being the integer number you fill in. In more traditional Arduino programming this might be represented as: for(int i = 0; i<4; i++){ //code to be repeated goes here } So you can see how convenient this loop block is! Drag the show frame of _sparkle_ animation block into the repeat _4_ times/do loop. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 17 of 61

The repeat/do and animation blocks are greyed out, since they don't sit inside of any loops that will be executed by the Circuit Playground Express. Move them as a unit into the on _buttona click_ loop. Increase the number of repetitions from 4 to 24, then upload the program to the Circuit Playground Express and test it out by pressing the left button. That's more like it! Now the rainbow animation plays until you click the left button, and you then get a moment of sparkle. Shake It To use our magic wand and sword props, it'll be much more fun to trigger the lights and sounds with motion instead of a button press. The Circuit Playground Express has a built in accelerometer that can be used to detect different types of motion. Lets swat out the button push input for a shake input. Chose the shake loop from the INPUT category. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 18 of 61

Drag the repeat/do loop (including it's contained show frame of animation block) into the shake loop. Get rid of the empty on _buttona click_ loop by clicking on it and pressing delete on you keyboard. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 19 of 61

Test the code on your board. Now, when you give it a good shake, the Circuit Playground Express will play back a bit of the sparkle animation, and then return to the rainbow! Let's make the sparkles even more magical by setting them to maximum brightness!! Make two duplicates of the set brightness block from the on start loop. Place one above the repeat _24_ times/do block, and one below it. Then, change tie value of the first one to 255. Test it on your board -- now, when you shake the Circuit Playground Express the sparkle animation will be super bright! Don't look directly at the NeoPixels at full brightness, they're massively bright! Picking Themes Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 20 of 61

For versatility, you can make your Circuit Playground Express work in different modes, depending on the prop with which you want to use it. Here's how you can use the selector switch on board to pick between two different color and animation themes, one for the wand and the second for the sword. Slide Switch Input Add an on switch moved _left_ loop. This is an input block, just like a button press or shake input, but uses the two position slide switch that's built onto the Circuit Playground Express. Duplicate the block and change the dropdown to make the on switch moved _right_ loop. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 21 of 61

Variables Next, we'll create a variable to help us check the state of the switch in other parts of the code. The variable is a named object that can store a value, in this case a number. Pick the set _item_ to block from the Make A Variable selections. This block not only declares the variable, but can be used to change the value of the variable. Duplicate the set _item_ to block, and then place one inside each of the on switch moved loops. Also, set the value of the one in the on switch moved _right_ loop to 1 instead of 0. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 22 of 61

A nice thing about variables is that we can give them descriptive names that help you out. Let's rename the item variable to theme. That way you'll know whenever you see it in you code that this variable is used to store the value of which theme we're using: a 0 means Wand, and a 1 means Sword. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 23 of 61

Conditionals You'll want to have the program logic react differently depending on the state of the slide switch. If the switch is on the left, then it will play lights and sounds for the Wand when shaken If the switch is on the right, then it will play lights and sounds for the Sword when shaken To do this, you'll use a conditional operator called an if/then loop. Add an if/then loop from the LOGIC category. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 24 of 61

We now need to create a block that lets the if/then loop know what condition needs to be met for it to evaluate as true or false. In our case, one loop will be true if theme equals 0, and the other will be true if theme equals 1. From the LOGIC category, click on the 0 = 0 block. Also, from the VARIABLES category, click on the theme block. This will allow you to compare the variable to a number (0 or 1). Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 25 of 61

Drag the theme variable onto the first 0 in the 0 = 0 comparison block -- it'll replace the first 0. Then, drag the theme = 0 block on top of the true segment of the if/then loop. This loop is now set so that whenever the theme is set to 0 (the left position of the slide switch) it will run whatever code blocks are inside of the then section of the loop. Move the set of blocks out of the shake loop and into the if/then loop. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 26 of 61

Then, put the whole thing back into the shake loop. So, here's what this section of your code now does: 1. Checks the slide switch 2. Sets the variable called theme to a 0 or 1 depending on switch position 3. Checks the accelerometer to feel for a shake 4. Compares the value of theme to the number 0 5. If the theme does equal 0, then it will bump up the brightness, play 24 frames of the sparkle animation, and then set the brightness back down Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 27 of 61

Try this out on your board now. You'll see that with the selector switch in the left position, it behaves the same as before, running the rainbow animation until shaken, at which point it plays the sparkle animation for a moment. With the switch in the right position, however, the shake has no effect. Now that that's working, let's create a loop to play a different animation when the switch is in the right position. Duplicate the entire if _theme_ = 0 loop, and then move the copy inside of the shake loop. Then, change the if statement value to 1, this means it will execute all code blocks inside of the if statement when the switch is to the right. In this right switch loop, change the repeats to 300 and the animation to comet. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 28 of 61

Test it out on the board -- you now get two different shake animations depending on the position of the switch! Let's use the same method to change the animation inside of the forever loop. This way, if you're using the Circuit Playground Express for the magic wand, you can set the switch to the left for rainbows and sparkles, or, set the switch to the right for sword mode which includes comets and color wipes! Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 29 of 61

Match your block layout to the one shown here, then test it out on your board. Sound Now that you've gotten lights and action happening, it's time to add sound! To begin with, click the MUSIC category, then click on the MORE button, then chose the set speaker volume button. Add this block to the on start loop, so that the speaker volume is initialized on startup. To avoid bothering your neighbors, you can pick a low volume, such as 20 as seen here, or really blast it up to 255! Next, create a block that makes some sound. Let's chose the play melody _power up_ block. Place this inside the "if Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 30 of 61

left switch" loop of the shake loop. This means that if the condition "shake" is met, and the condition "switch is in the left position" is met, the sound will play. You can select from a list of pre-made melodys, and then try them out by clicking the "shake" button on the Circuit Playground Express simulator. If you don't hear anything, try flipping the virtual selector switch to the other side. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 31 of 61

Duplicate the play melody block, insert the copy into the right switch if loop, and then choose a different melody to play during sword swing maneuvers! Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 32 of 61

Code Cleanup It works! You're almost ready to attach your Circuit Playground Express to a wand or sword prop! But before you do so, let's clean up the code a little bit. Often, when you are first creating a program, you'll copy and paste whole chunks of code that are meant to do similar things, and then change them slightly. This works great, but you can then optimizing things by removing redundant code blocks. Let's have a look at the shake loop. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 33 of 61

Since we built the first if/then loop and then duplicated it, we've got more copies of the set brightness 255 and set brightness 40 blocks than we need. Since we want to up the brightness whenever we shake, regardless of the position of the switch, that block can live outside of the if/then loops. The same is true of the block lowering the brightness once the shake is finished. Move one set brightness 255 block above and outside of the if/then loops, and one set brightness 40 below and outside, as seen here. Then, delete the extras. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 34 of 61

That's looking cleaner already! Next, let's consider the two if/then loops. Since our switch only has two states -- left and right -- we know that if the switch isn't to the left, then it must be to the right. This is a great place to switch from two if/then loops to a single if/then else loop. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 35 of 61

The if/then else loop will replace both if/then loops. Drag the first condition -- theme = 0 -- over to the condition block of the if/then else loop. Then, move the play melody, repeat times, and show frame of animation, blocks from the first if/then loop to the then section of the if/then else loop. Do the same with the blocks in the second if/then loop, moving them to the else section of the if/then else loop. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 36 of 61

Replace the two empty if/then loops with the if/then else loop. Your code is more streamlined now! You can also optimize the forever loop in the same fashion, to look like this. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 37 of 61

Upload this code to your Circuit Playground Express and test it out. It should work identically, but it's good to know how you can optimize your code, especially if you start to create longer, more complex programs. Here's what the final program looks like. Feel free to experiment now by changing things around, or making a whole new program from scratch!! Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 38 of 61

Prep the Circuit Playground 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. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 39 of 61

CircuitPlaygroundMakeBelieve.zip https://adafru.it/scp 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 Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 40 of 61

Upgrade a Prop Sword Here we have a very nice, off the shelf foam sword. It sure looks like it could use some light and sound effects! There's a flat part on the sword guard that looks perfect for attaching the Circuit Playground. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 41 of 61

Once you've uploaded your code to the Circuit Playground, it's time to connect it to the AAA battery pack and attach it all to your prop weapon. Depending on your prop, you can choose different methods to attach it. Small zip ties are great because the are sturdy, fit through the holes on the Circuit Playground, and can be customized to different lengths by adding one zip tie to the end of another. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 42 of 61

Here, you can see the Circuit Playground zip tied to a foam sword. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 43 of 61

After pulling the zip ties tight, use diagonal cutters or scissors to clip the exess length from the ends. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 44 of 61

Those little zip tie ends can be sharp after cutting -- use nail clippers to round them down and avoid a scratch! Next, feed the battery cable under the backside of the Circuit Playground, under the zip ties, then plug it in. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 45 of 61

The battery pack fits nicely on the backside of the sword guard, also using zip ties. Create a zip tie harness for the battery pack by threading two through the back of the existing ones, double them with two more zip ties, then secure the battery pack. You can create an additional point of security with a set of three zip ties running around the battery pack horizontally. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 46 of 61

Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 47 of 61

Tighten the zip ties and clip the excess ends. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 48 of 61

Swing it to try it out! Next, we'll look at a more customized approch to building a prop magic wand from scratch to fit the Circuit Playground. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 49 of 61

3D Printed Magic Wand This magic wand was designed specially to use the Circuit Playground as its centerpiece effect. It is 3D printed with a mix of translucent and opaque materials, has a mounting plate onto which you can secure the Circuit Playground, as well as an integrated LiPoly battery and on/off switch. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 50 of 61

In addition to the Circuit Playground, LiPoly battery, and switch, you'll also need four M3 x 6mm screws and nuts, two M3 x 16mm screws and nuts, and four M2 x 6mm screws and nuts. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 51 of 61

Here are the files you'll use to print it. starwand_stl.zip https://adafru.it/scq Print the star parts in a translucent material, such as a natural PLA. The rest of the parts can be printed in any material you choose, and even painted for a more finished look. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 52 of 61

The piezo speaker on the Circuit Playground isn't terribly loud, so there are small start cutouts in the shell to help the sound escape. The top star can also be used to access the reset button, should you need it. Next you'll assemble the wand. Make sure you've uploaded the Make Believe sketch to the Circuit Playground, then mount it to the mount plate using 2.5mm screws and nuts. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 53 of 61

Next, place the switch into the handle cutout, feeding the plug ends through their respective holes for the battery and the Circuit Playground board. Plug the battery into the switch and the switch into the Circuit Playground's JST connector. Test the switch to make sure the Circuit Playground turns on. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 54 of 61

Place the battery in its place inside the lower handle bottom, then fasten the bottom with an M3 x 16mm screw and nut. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 55 of 61

Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 56 of 61

Note how the lower switch wire and battery wire are tucked into the handle with the connectors accessiblye through the handle opening. This is so you can pull them out and dissconnect them for battery charging without unscrewing the wand. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 57 of 61

Sandwich the Circuit Playground and mount between the two star halves, feeding the switch wire through the wire channel at the base of the star top half. Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 58 of 61

Begin the assembly in this order: Top half of handle Trim piece Star top Circuit Playground and mount Star bottom Bottom half of handle Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 59 of 61

Screw the handle top parts together with the other M3 x 16mm screw, placing the nut on the opposite side. Add the remaining trim pieces on the top and bottom of the stars and screw them together with M2 x 8mm screws and nuts. Now, you can turn on the wand and wave and flick it to maximum magical effect. Should the battery ever require Adafruit Industries https://learn.adafruit.com/sword-and-wand-prop-effects-with-circuit-playground Page 60 of 61

charging, you can pull the charging plug through the port in the handle and plug it into a LiPoly USB charger. Remember, this guide is just a leaping off point for using the Circuit Playground to add motion triggered effects to any prop you like! Adafruit Industries Last Updated: 2018-01-13 05:32:53 AM UTC Page 61 of 61