# NeoPixie Dust Bag with Circuit Playground Express

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/043/314/medium800/circuit_playground_zarina_crop.jpg?1498792178)

How can your&nbsp;fairy costume be&nbsp;complete without a glowing pixie dust bag?! It sparkles and blinks, and you can squeeze&nbsp;the touch sensor wire to change the&nbsp;colors on the beautifully twinkling&nbsp;NeoPixel ring! This fun, sophisticated-looking prop is easy to build&nbsp;with absolutely no soldering required.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/301/medium800thumb/circuit_playground_squeezeBag03.jpg?1498693320)

This project&nbsp;updates and simplifies the classic [GEMMA-based](../../../neopixel-pixie-dust-bag/overview)build&nbsp;by using the [**Circuit Playground Express**](https://www.adafruit.com/product/3333) -- what used to use multiple pieces of hardware is now built into a single board! Plus, all of the programming is done with the user-friendly graphical interface of MakeCode, so no need to type code or use the Arduino IDE if you don't want to.

Besides the Circuit Playground Express, you also need:

- 3 AAA battery pack with on/off switch, or
- 3.7V Lithium Ion battery with charger for a more compact build
- short wire alligator clip test leads
- translucent pixie dust bag
- small plastic bag
- flake salt, such as Morten's Kosher salt, used to&nbsp;as light diffusing "pixie dust"

![](https://cdn-learn.adafruit.com/assets/assets/000/043/277/medium800/circuit_playground_IMG_0310.jpg?1498681676)

# NeoPixie Dust Bag with Circuit Playground Express

## Code It

![](https://cdn-learn.adafruit.com/assets/assets/000/043/303/medium800thumb/circuit_playground_inBag.jpg?1498764160)

Your NeoPixie dust bag must&nbsp;twinkle beautifully -- what better way to do that than set&nbsp;the LEDs to a solid color and then randomly sparkle some of them white? You'll also want to be able to change the colors by tapping the capacitive touch sensor.&nbsp;

You can program all of these effects without typing a line of code, simply by 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&nbsp;[tutorial here on the basics of MakeCode](../../../../makecode?view=all)&nbsp;for Circuit Playground Express to make sure you know the basics of creating and uploading your code.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/043/165/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_1.jpg?1498660013)

# Setup

You'll begin with a&nbsp;nice clean canvas -- nothing but a single, empty **forever** loop block. This is where all of the repeating command blocks will live, running over and over and over again.

Let's also add an **on start** block to set one parameter from the beginning -- this is a good place for any commands that need to run once each time the Circuit Playground Express is turned on or reset. Think of it as a sort of initialization block.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/166/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_1b.jpg?1498660021)

From the **Light&nbsp;** category, add&nbsp;a&nbsp; **set brightness&nbsp;** block to the&nbsp; **on start&nbsp;** block and set the value to something moderately bright, say 80.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/167/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_2.jpg?1498660028)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/168/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_3.jpg?1498660034)

# Animation

Next, you'll light up the NeoPixel ring using&nbsp; **photon&nbsp;** blocks.&nbsp;

Info: 

From the&nbsp; **Light** category, grab a&nbsp; **photon pen up&nbsp;** block and place it into the&nbsp; **forever&nbsp;** loop. Then, change the dropdown to&nbsp; **pen down**.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/169/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_4.jpg?1498660041)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/171/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_5.jpg?1498660048)

You'll want to light up and color your NeoPixels by moving the&nbsp;photon pen around while the pen is down, so add a&nbsp; **photon forward&nbsp;**** by 1&nbsp; **block to the&nbsp;** forever&nbsp;**loop.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/173/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_6.jpg?1498660245)

To create the organic, irregular sparkle pattern, you'll have the photon pen move a random number of positions (between&nbsp;0-4), by adding a **pick random 0 to 4&nbsp;** block to the&nbsp; **photon forward by&nbsp;** block.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/174/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_7.jpg?1498660245)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/175/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_8.jpg?1498660246)

You'll do the same sort of trick to vary the brightness, using the&nbsp; **set brightness block&nbsp;** and another&nbsp; **pick random** block, with the value range set from **0 to 40**

![](https://cdn-learn.adafruit.com/assets/assets/000/043/176/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_9.jpg?1498660247)

To slow things down just a touch, add in a slight pause with the&nbsp;**pause (ms)&nbsp;**block.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/177/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_10.jpg?1498660248)

Here's what the animation now looks like -- go ahead and test it out!

![](https://cdn-learn.adafruit.com/assets/assets/000/043/178/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_11.jpg?1498660249)

# Color Touch

By default the LEDs will light up red. Red is nice, but how about some other colors, too, when the mood strikes? You'll now add touch input that allows one of the capacitive touch pads of the Circuit Playground Express to switch the color values every time you tap it.

From the **Input&nbsp;** category, add an&nbsp; **on buttonA click** block.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/179/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_12.jpg?1498660250)

Change the input to one of the pin pads, in this case&nbsp; **pin A5**. (Any of the seven pin A pads will work as capacitive touch pads.)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/180/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_13.jpg?1498660251)

Change the input mode to&nbsp; **down** instead of&nbsp; **click**. This means the input condition is met the moment you touch the pad, not when you touch and release.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/181/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_14.jpg?1498660252)

Add a&nbsp; **set all pixels to red&nbsp;** block from the **light** &nbsp;category to the&nbsp; **on pin A5 down&nbsp;** block.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/182/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_15.jpg?1498660291)

To make the ring flash white when the pad is touched, change the dropdown from&nbsp; **red&nbsp;** to&nbsp; **white.**

![](https://cdn-learn.adafruit.com/assets/assets/000/043/183/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_16.jpg?1498660292)

# Variable Color

To change the color of the photon in the&nbsp; **forever&nbsp;** block, we'll use a variable. This variable, called "pixieColor", will store a value that changes each time you touch the capacitive pad, and the value will be used by the **photon set color&nbsp;** block.

In the&nbsp; **Variables&nbsp;** category, click the&nbsp; **Make a Variable&nbsp;** button, then type the name&nbsp; **pixieColor&nbsp;** and click&nbsp; **Ok.**

![](https://cdn-learn.adafruit.com/assets/assets/000/043/184/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_17.jpg?1498660293)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/185/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_18.jpg?1498660294)

Drage the&nbsp; **change item by 1&nbsp;** block into the **on pin A5 down&nbsp;** block, then change the dropdown to your&nbsp; **pixieColor&nbsp;** variable. So that the color change is more dramatic, set the change value to 50.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/186/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_19.jpg?1498660295)

Add a **photon set pen hue** block to the&nbsp; **forever&nbsp;** loop, just under the&nbsp; **photon pen down&nbsp;** block.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/049/478/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express.jpg?1513804627)

Instead of the default 0 value, drag an instance of the&nbsp; **pixieColor&nbsp;** variable block on to the&nbsp; **photon set pen hue.**

![](https://cdn-learn.adafruit.com/assets/assets/000/049/479/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express_2.jpg?1513804712)

![](https://cdn-learn.adafruit.com/assets/assets/000/049/480/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express_3.jpg?1513804792)

# Simulate It

Test out the color change now by clicking the gold pad on the Circuit Playground Express simulator at pad A5. You'll see the color change each time you click it.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/189/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_22.jpg?1498660297)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/190/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_23.jpg?1498660298)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/191/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_24.jpg?1498660299)

# Pseudo ON/OFF

You may not always want your NeoPixie Dust Bag to sparkle, but it isn't convenient to unplug the battery all the time, so let's use the on-board slide switch to turn off the LEDs.

Grab an&nbsp; **on switch moved left&nbsp;** block from the&nbsp; **Input&nbsp;** category, then duplicate it and set the second one's dropdown to&nbsp; **right.**

![](https://cdn-learn.adafruit.com/assets/assets/000/043/192/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_25.jpg?1498660299)

Like you did before, create a new variable, this time naming it "ON/OFF".

![](https://cdn-learn.adafruit.com/assets/assets/000/043/193/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_26.jpg?1498660300)

Drag a&nbsp; **set item to 0&nbsp;** block into each switch block, and then change their variable dropdown choices to&nbsp; **ON/OFF.&nbsp;** The left position will be ON, so set the value to 1, leaving the right position to 0.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/194/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_27.jpg?1498660301)

# Conditional If/Then/Else

So you now have a variable named ON/OFF that changes depending on the slide switch position. But how do you actually use that to control the lights? The answer is with a conditional&nbsp; **if then else&nbsp;** block.&nbsp;

This block does two things: it tests if a certain condition is met, and then it executes the proper set of blocks depending on that answer.

In our case:&nbsp; **if&nbsp;** the variable&nbsp; **ON/OFF&nbsp;** is equal to 1,&nbsp; **then&nbsp;** play our animation blocks,&nbsp; **else,&nbsp;** set all the pixels to black.

From the&nbsp; **Logic&nbsp;** category, get an&nbsp; **if then else&nbsp;** block and place it in the&nbsp; **forever&nbsp;** loop. Then place all of the animation blocks inside the&nbsp; **then&nbsp;** section.

![](https://cdn-learn.adafruit.com/assets/assets/000/049/482/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express_28.jpg?1513806323)

![](https://cdn-learn.adafruit.com/assets/assets/000/049/483/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express_29.jpg?1513806372)

To test our condition, we'll need to get a&nbsp; **0 = 0&nbsp;** block from the&nbsp; **Logic&nbsp;** category and place that at the end of the&nbsp; **if&nbsp;** statement.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/197/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_30.jpg?1498660303)

![](https://cdn-learn.adafruit.com/assets/assets/000/049/484/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express_31.jpg?1513806425)

Place an&nbsp; **ON/OFF&nbsp;** variable into the first slot, and change the second slot to&nbsp; **1.&nbsp;** This means now that when the slide switch is to the left, the variable will be equal to 1 and the animation will play.

![](https://cdn-learn.adafruit.com/assets/assets/000/049/485/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express_32.jpg?1513806465)

Now, put a&nbsp; **set all pixels to&nbsp;** block inside the **else** section, and change the dropdown to&nbsp; **black.**

![](https://cdn-learn.adafruit.com/assets/assets/000/043/200/medium800/circuit_playground_PixieDustBag_-_Adafruit_Circuit_Playground_Express_33.jpg?1498660305)

You finished programming your NeoPixie Dust Bag! Upload it to the Circuit Playground Express and then we'll move on to dressing it up with a battery, bag, and capacitive switch.

![](https://cdn-learn.adafruit.com/assets/assets/000/049/486/medium800/wearables_PixieDustBag_-_Adafruit_Circuit_Playground_Express_34.jpg?1513806548)

Info: 

https://makecode.com/_Fh3ca05LjfWe

# NeoPixie Dust Bag with Circuit Playground Express

## Build and Use It

![](https://cdn-learn.adafruit.com/assets/assets/000/043/280/medium800/circuit_playground_IMG_0310_2k.jpg?1498682379)

# Touch Sensor

To make it easier to change colors when the Circuit Playground Express is in the bag, extend the Pin A5 sensor with a loop of wire. You can simply clip the alligator lead to the pad on both ends as seen here.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/281/medium800/circuit_playground_IMG_0312_2k.jpg?1498682390)

Plug in your battery, make sure the slide switch is set to the left, and then squeeze the wire while holding the board in order to trip the sensor and change colors.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/282/medium800/circuit_playground_IMG_0315_2k.jpg?1498682427)

# Bag in a Bag

You'll use the salt to diffuse the light and make the bag look like it's full of pixie dust. To keep the salt off of the electronics, place them inside the plastic bag, then place all of that into the pixie dust bag.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/283/medium800/circuit_playground_IMG_0376_2k.jpg?1498682433)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/284/medium800/circuit_playground_IMG_0377_2k.jpg?1498682438)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/285/medium800/circuit_playground_IMG_0378_2k.jpg?1498682442)

Now, fill the pixie dust bag with salt. Instant pixie dust!

![](https://cdn-learn.adafruit.com/assets/assets/000/043/286/medium800/circuit_playground_IMG_0379_2k.jpg?1498682446)

You can hold the bag's wire loop and then squeeze the pixie dust &nbsp;to change the color! Your capacitance is measured by the on-board sensor, and it works best when you have a hand near the board and the other squeezing the wire.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/287/medium800/circuit_playground_IMG_0382_2k.jpg?1498682451)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/288/medium800/circuit_playground_IMG_0385_2k.jpg?1498682455)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/289/medium800/circuit_playground_IMG_0386_2k.jpg?1498682460)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/290/medium800/circuit_playground_IMG_0410_2k.jpg?1498682464)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/291/medium800/circuit_playground_IMG_0415_2k.jpg?1498682468)

Now go off and spread magic -- maybe you can even teach someone to fly!


## Featured Products

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### 3 x AAA Battery Holder with On/Off Switch, JST, and Belt Clip

[3 x AAA Battery Holder with On/Off Switch, JST, and Belt Clip](https://www.adafruit.com/product/3286)
This battery holder connects 3 AAA batteries together in series for powering all kinds of projects. We spec'd these out because the box is slim, and 3 AAA's add up to about 3.3-4.5V, a very similar range to Lithium Ion/polymer (Li-Ion) batteries, plus it has&nbsp;a nifty&nbsp;on-off...

In Stock
[Buy Now](https://www.adafruit.com/product/3286)
[Related Guides to the Product](https://learn.adafruit.com/products/3286/guides)
### Short Wire Alligator Clip Test Lead (set of 12)

[Short Wire Alligator Clip Test Lead (set of 12)](https://www.adafruit.com/product/1592)
Connect this to that without soldering using these handy mini alligator clip test leads. Approximately 4.5" overall cables with alligator clip on each end, color coded. You get 12 pieces in 6 colors. Strong and grippy, these always come in handy! We often use these in conjunction with a...

In Stock
[Buy Now](https://www.adafruit.com/product/1592)
[Related Guides to the Product](https://learn.adafruit.com/products/1592/guides)
### Lithium Ion Polymer Battery - 3.7v 500mAh

[Lithium Ion Polymer Battery - 3.7v 500mAh](https://www.adafruit.com/product/1578)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 500mAh for a total of about 1.9 Wh. If you need a larger (or smaller!) battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1578)
[Related Guides to the Product](https://learn.adafruit.com/products/1578/guides)
### Adafruit Micro Lipo - USB LiIon/LiPoly charger

[Adafruit Micro Lipo - USB LiIon/LiPoly charger](https://www.adafruit.com/product/1304)
Oh so adorable, this is the tiniest little lipo charger, so handy you can keep it any project box! Its also easy to use. Simply plug in the gold plated contacts into any USB port and a 3.7V/4.2V lithium polymer or lithium ion rechargeable battery into the JST plug on the other end. There are...

In Stock
[Buy Now](https://www.adafruit.com/product/1304)
[Related Guides to the Product](https://learn.adafruit.com/products/1304/guides)
### Circuit Playground Express Advanced Pack

[Circuit Playground Express Advanced Pack](https://www.adafruit.com/product/2769)
 **Circuit Playground Express** &nbsp;is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to program....

Out of Stock
[Buy Now](https://www.adafruit.com/product/2769)
[Related Guides to the Product](https://learn.adafruit.com/products/2769/guides)

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Make It Log](https://learn.adafruit.com/make-it-data-log-spreadsheet-circuit-playground.md)
- [Creating and sharing a CircuitPython library](https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library.md)
- [Easter Egg Light Stand](https://learn.adafruit.com/easter-egg-light-stand.md)
- [Circuit Playground D6 Dice](https://learn.adafruit.com/circuit-playground-d6-dice.md)
- [Gemma-Powered NeoPixel LED Sound Reactive Drums](https://learn.adafruit.com/gemma-powered-neopixel-led-sound-reactive-drums.md)
- [Glowing Lotus Flower - Electronic Origami for Beginners](https://learn.adafruit.com/glowing-lotus-flower-electronic-origami-for-beginners.md)
- [Hammer Time Mini Golf Hazard with Crickit](https://learn.adafruit.com/mini-golf-hammer-time-circuit-playground-crickit.md)
- [Cosplay Glow Fur Raver Bandolier](https://learn.adafruit.com/cosplay-glow-fur-raver-bandolier.md)
- [Animatronic Glowing Medusa Headdress](https://learn.adafruit.com/animatronic-glowing-medusa-headdress.md)
- [Digital Fidget Spinner](https://learn.adafruit.com/digital-fidget-spinner.md)
- [Crystal Glow Knuckles](https://learn.adafruit.com/crystal-glow-knuckles.md)
- [Giant Mechanical Keyboard](https://learn.adafruit.com/giant-control-alt-delete.md)
- [Dance-Reactive Tutu Sparkle Skirt](https://learn.adafruit.com/dance-reactive-tutu-sparkle-skirt.md)
- [LEGO Head Lamp with Audio](https://learn.adafruit.com/lego-head-lamp-with-audio.md)
- [Adabot Operation Game](https://learn.adafruit.com/adabot-operation-game.md)
