# Circuit Playground & Fiber Optics

## Intro & Setup

https://youtu.be/tI11D4ws83g

Circuit Playground is a really fun, really easy to use micro controller that is a great way to add sensors and interactivity to your project without a whole lot of fuss and soldering.

It's got a built in motion sensor, a sound sensor, a light sensor, and a temperature sensor, as well as a built in speaker and 10 neopixels, ready to use right out of the box.&nbsp; I'm just starting to explore the fun things this board can do.

Today we're going to&nbsp;play with the onboard neopixels and add fiber optics or light pipe to make your project&nbsp;dance and shine.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/470/medium800/led_pixels_fiber_optic_circuit_playground.jpg?1487557076)

# Materials

- Circuit Playground
- Battery (liPoly, AAA or USB) &nbsp;- optional
- Light Pipe or Fiber Optics
- Hot Glue or Superglue

## Tools

- 3d Printer
- Sharp scissors or snips

Note: If you don't have a 3d Printer, you can easily just order&nbsp;the case from [Shapeways](https://www.shapeways.com/product/K5Q5EXPEF/circuit-playground-light-pipe).

&nbsp;

# Before You Start

If this is your first foray into the world of arduino-based microcontrollers, you'll need to install some software first. &nbsp;Head over to the [Circuit Playground Lesson 0 guide](../../../circuit-playground-lesson-number-0/install-software-linux?view=all#intro) for detailed installation and setup instructions. &nbsp;

You'll only need to do all this once, so be a little patient if it seems like a lot! &nbsp;This is actually the hardest part.

# Circuit Playground & Fiber Optics

## Code

Accessing the onboard neopixels is easy to do. &nbsp;There is some example code to get you started in the Circuit Playground library. &nbsp;In Arduino, open: &nbsp;

Examples \> Adafruit Circuit Playground \> Hello\_CircuitPlayground \> Hello\_Neopixels

![](https://cdn-learn.adafruit.com/assets/assets/000/039/459/medium800/led_pixels_hello_neopixels.jpg?1487525634)

This code shows two different ways to send color data to your neopixels, and an easy way to blink them on and off. &nbsp;Take a look &nbsp;at these five lines:

```auto
  CircuitPlayground.setPixelColor(0, 255,   0,   0);
  CircuitPlayground.setPixelColor(1, 128, 128,   0);
  CircuitPlayground.setPixelColor(2,   0, 255,   0);
  CircuitPlayground.setPixelColor(3,   0, 128, 128);
  CircuitPlayground.setPixelColor(4,   0,   0, 255);
```

The first argument in each line -- in this case, 0-4&nbsp;--&nbsp;is the pixel number. &nbsp;(The pixels are numbered 0-9, since counting that way makes computers unreasonably happy.) &nbsp;When looking at the board with the USB port facing up, pixel 0 is located at 11:00, just to the left of the port. &nbsp;You can light up any pixel by calling&nbsp;its pixel number here. &nbsp;

The next three numbers correspond to values for red, green, and blue. &nbsp;0 is off, and 255 is full brightness for that color. &nbsp;The way neopixels work is by mixing different amounts of light from the red, green, and blue LEDs hidden inside each pixel. &nbsp;Play with changing these numbers within a range of 0-255 to get the color you want.

```auto
  CircuitPlayground.setPixelColor(6, 0x808000);
  CircuitPlayground.setPixelColor(7, 0x00FF00);
  CircuitPlayground.setPixelColor(8, 0x008080);
  CircuitPlayground.setPixelColor(9, 0x0000FF);
 
```

The next&nbsp;5&nbsp;lines show a slightly different way to set the color. &nbsp;The first argument still corresponds to the pixel number, and&nbsp;the next part is a Hexidecimal code -- you can always recognize these&nbsp;because you'll see&nbsp;the prefix "0x".

Hex codes are an easy way to get any color you want. &nbsp;Look for online [color pickers](http://www.colorpicker.com/) or desktop widgets to make your life easy. &nbsp;However, the colors will not always look the same on your neopixels as they do on your screen, especially with darker colors, so be ready for some experimentation.

https://www.youtube.com/watch?v=c56x1aj2CPA

These are just a couple of quick ways to get your lights up and running. &nbsp;Neopixels are also wonderful for running animations or reacting to some of the Circuit Playground's onboard sensors. &nbsp;Here are a few other guides and code samples that are fun to play with.

# Code Samples

- [Motion Sensor Response](../../../../circuit-playgrounds-motion-sensor/twinkle)
- [Analog Input Response](../../../../circuit-playground-analog-input/neopixel-fun)
- [Simon Game](../../../../circuit-playground-simple-simon/code-walk-through)
- [Adalight for Circuit Playground](../../../../adalight-for-circuit-playground/download-install)
- [Light Paintbrush](../../../../lightpaint-cplay/upload-the-light-paintbrush-code)
- [Magic Wand & Sword](../../../../sword-and-wand-prop-effects-with-circuit-playground/prep-the-circuit-playground)

You'll also find a lot more samples to play with in the Examples folder in the Circuit Playground library, including vu\_meter which lights up the pixels in response to sound. &nbsp;&nbsp;

Here's one more sample that gently animates the pixels in a rainbow or one of several&nbsp;other color palettes. &nbsp;The left button will change modes and the right button will turn the LEDs off.

NOTE: &nbsp;You will need to install the FastLED library in Arduino first (Sketch \> Include Library \> Manage Libraries...)

One other note: &nbsp;if you're using FastLED with Circuit Playground, be sure to include the Circuit Playground library FIRST and the FastLED library second, or you may run into problems.

```auto
#include <Adafruit_CircuitPlayground.h>
#include <FastLED.h>

#define LED_PIN     17
#define NUM_LEDS    10
#define COLOR_ORDER GRB

int BRIGHTNESS =255;
int STEPS      =25;
int NUM_MODES   =5;

CRGB leds[NUM_LEDS];

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

int ledMode = 0;
bool leftButtonPressed;
bool rightButtonPressed;

void setup() {
  CircuitPlayground.begin();
  FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  currentBlending = LINEARBLEND;

  
}

void loop()  {

  leftButtonPressed = CircuitPlayground.leftButton();
  rightButtonPressed = CircuitPlayground.rightButton();

  if (leftButtonPressed) {
    ledMode=ledMode+1;
    delay(300);
    if (ledMode > NUM_MODES){
    ledMode=0;
     }
  }
    if (rightButtonPressed) {
    ledMode=99;
  
    }
  
 switch (ledMode) {
       case 0: currentPalette = RainbowColors_p; rainbow(); break; 
       case 1: currentPalette = OceanColors_p; rainbow(); break; 
       case 2: currentPalette = ForestColors_p; rainbow(); break;                      
       case 3: currentPalette = PartyColors_p; rainbow(); break; 
       case 4: currentPalette = HeatColors_p; rainbow(); break; 
       case 5: currentPalette = RainbowStripeColors_p; rainbow(); break;    
       case 99: CircuitPlayground.clearPixels(); break;
       
}
}
void rainbow()
{
  
  static uint8_t startIndex = 0;
  startIndex = startIndex + 1; /* motion speed */

  FillLEDsFromPaletteColors( startIndex);

  FastLED.show();
  FastLED.delay(10);}

//this bit is in every palette mode, needs to be in there just once
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
  uint8_t brightness = BRIGHTNESS;
  
  for( int i = 0; i < NUM_LEDS; i++) {
    leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
    colorIndex += STEPS;
  }
}

```

# Circuit Playground & Fiber Optics

## 3d Printing

This is a remix of the [3d Printed Circuit Playground Yo Yo project](../../../../circuit-playground-yoyo/3d-printing) by the Ruiz Brothers. &nbsp;

There are 4&nbsp;different pieces to print: &nbsp;the base, the top, the buttons, and the cover which holds the fiber optics or light pipe.

If you don't have access to a 3d printer, you can order the whole case&nbsp;ready-to-go from Shapeways.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/613/medium800/led_pixels_case_render.jpg?1487723585)

[Download from Thingiverse](http://www.thingiverse.com/thing:2122751)
[Order from Shapeways](https://www.shapeways.com/product/K5Q5EXPEF/circuit-playground-light-pipe)
## Slice Settings

Below are some recommended slice settings. These parts were printed on an Up! Mini.

- .15mm layer height
- 220C extruder / PrintInZ Skin
- 20% infill
- 4&nbsp;top/bottom layers
- 2 shells / parameters
- 40mm/s printing speed

# Circuit Playground & Fiber Optics

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/039/614/medium800/led_pixels_cp_pieces_buttons.jpg?1487723838)

Place the Circuit Playground inside the base, with the USB port facing the smaller hole nad the battery connector lined up with the larger hole. &nbsp;Secure it with a little dab of hot glue on the case's pillars.

Set the 3d printed button pieces aside for a minute. &nbsp;

Place&nbsp;the cover&nbsp;into the top and tape it in place from the outside.&nbsp; Screw the top onto the base. &nbsp;Once the top is tight, adjust the cover's orientation so the holes line up perfectly with the neopixels and buttons.

Unscrew the top, being careful to keep the orientation right, and glue the cover and top together securely.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/615/medium800/led_pixels_cp_upsidedown.jpg?1487723939)

Turn the lid upside down and set&nbsp;the buttons small-side-down into the button holes. &nbsp;Screw or press the base with the Circuit Playground inside into place so the neopixels are aligned and the buttons contact the Circuit Playground's buttons. &nbsp;

My 3d printed threads didn't hold very well, so I secured the top with hot glue.

Plug your battery or USB cable in and make sure the lights are lined up perfectly through the holes and the buttons are satisfyingly clicky.

The left button will cycle through color modes and the right button will turn the LEDs off. &nbsp;

**Warning!** &nbsp;this button does **not** turn the Circuit Playground board off entirely, so if you're running from a battery, keeping it semi-off like this will drain your battery eventually -- unplug your battery if you want it off completely.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/039/616/medium800/led_pixels_cp_top_on.jpg?1487724102)

The holes are sized to snugly fit 2.75mm light pipe. &nbsp;The best source I've found for this is these cheesy [light up shoelaces](https://www.amazon.com/Joylive-Fiber-Optic-Flash-Shoelaces/dp/B0107UFTQM/ref=sr_1_11?s=apparel&ie=UTF8&qid=1487554312&sr=1-11&nodeID=7141123011&keywords=light+up+shoelaces)&nbsp;(available everywhere!)

With your LEDs on full brightness these will glow for up to 3 feet, though the light does get quite a bit dimmer toward the end. &nbsp;I find they're most satisfying if kept to a length of 1-1.5 feet.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/617/medium800/led_pixels_cp_fiber_lightpipe.jpg?1487724139)

Or you can use&nbsp;fiber optics. &nbsp;There are two different kinds: end glow and side glow. &nbsp;The side glow are my favorite since they glow along their entire length. &nbsp;End glow are useful if you just want a single floating point of light at the end of each strand, also a beautiful effect.&nbsp;

My favorite source for fiber optic cable is [Weidamark lighting](http://www.wiedamark.com/fiberopticcable.aspx). &nbsp;They've got loads of options and sell the fibers by the foot. &nbsp;(Note: fiber optic solid core side glow appears to be the same stuff as the LED shoelace light pipe mentioned above).&nbsp;Order in any size bundles; you can easily separate them down to the right size bunches. &nbsp;

I can fit about 10 fibers in each 3d printed hole, so if you use all 10 holes you'll want around 100 fibers. &nbsp;Like the light pipe, these seem to be brightest and cheeriest in the first 1.5 feet or so. &nbsp;After that they do still glow but get a little dimmer. &nbsp;If you need more length than that, I'd recommend going with end-glow.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/618/medium800/led_pixels_cp_fiberoptics.jpg?1487724162)

Trim the fibers sharply and cleanly with a pair of snips or a hot knife. &nbsp;The cleaner the cut, the brighter the fiber will be. &nbsp;Start by slipping around 8&nbsp;fibers into the hole, and then keep adding fibers to the middle of the bundle until they're nice and snug.

If this will be going on a costume or art car, or something that will move a lot, it doesn't hurt to add some extra hot glue around the outside of the fiber holes to secure them.

DO NOT USE SUPERGLUE HERE. &nbsp;Most superglues will degrade the fiber optic cable and it'll stop glowing and break. &nbsp;Sad Christmas.

# Circuit Playground & Fiber Optics

## Project Ideas

Well that was easy. &nbsp;But.... what do I DO with this thing?

- Mardi Gras Mask accessory
- Top Hat Topper
- Kid's science fair volcano
- Glowing puppet hair
- Flower Bouquet Enhancer
- Pot Holder
- Night Light
- Showgirl Headdress

You can also use end-glow light pipe to put glowing eyes or spots of color into hard-to-reach areas of your costume or project, without messing around with breakable wires. &nbsp;Post your project in the Adafruit Forum!

![](https://cdn-learn.adafruit.com/assets/assets/000/039/469/medium800/led_pixels_cp_flowerbouquet.jpg?1487556226)

![](https://cdn-learn.adafruit.com/assets/assets/000/039/471/medium800/led_pixels_cp_fiber-headdress.jpg?1487557175)

![](https://cdn-learn.adafruit.com/assets/assets/000/039/472/medium800/led_pixels_cp_fiber_mardigras.jpg?1487557497)


## Featured Products

### Circuit Playground Classic

[Circuit Playground Classic](https://www.adafruit.com/product/3000)
Would you like to learn electronics, with an all-in-one board that has sensors and LEDs built in? **Circuit Playground** is here - and it's the best way to practice programming on real hardware with no soldering or sewing required!

This is the **Classic**...

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

[Lithium Ion Polymer Battery - 3.7v 1200mAh](https://www.adafruit.com/product/258)
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 1200mAh for a total of about 4.5 Wh. If you need a larger battery, <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/258)
[Related Guides to the Product](https://learn.adafruit.com/products/258/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)

## Related Guides

- [Introducing Circuit Playground](https://learn.adafruit.com/introducing-circuit-playground.md)
- [NeoPixel NanoRing](https://learn.adafruit.com/neopixel-nanoring-gemma.md)
- [Circuit Playground Analog Input](https://learn.adafruit.com/circuit-playground-analog-input.md)
- [Energy Budgets](https://learn.adafruit.com/energy-budgets.md)
- [NeoPixel Basketball Hoop](https://learn.adafruit.com/neopixel-mini-basketball-hoop.md)
- [Easy Sparkle Pocket T-Shirt](https://learn.adafruit.com/easy-sparkle-pocket-t-shirt.md)
- [Laser Dog Goggles](https://learn.adafruit.com/laser-dog-goggles.md)
- [Light-Up Angler Fish Embroidery](https://learn.adafruit.com/light-up-angler-fish-embroidery.md)
- [Animated NeoPixel Glow Fur Scarf](https://learn.adafruit.com/animated-neopixel-gemma-glow-fur-scarf.md)
- [Make a Snow Globe with Circuit Playground Express & MakeCode](https://learn.adafruit.com/make-a-snowglobe-with-circuit-playground-makecode.md)
- [Gemma Color Touch Pendant Necklace](https://learn.adafruit.com/gemma-color-touch-pendant-necklace.md)
- [Digital Fidget Spinner](https://learn.adafruit.com/digital-fidget-spinner.md)
- [Circuit Playground Slouch Detector](https://learn.adafruit.com/circuit-playground-slouch-detector.md)
- [Circuit Playground Express Rocket Lamp](https://learn.adafruit.com/cpx-rocket-lamp.md)
- [Glowing Beehive Hairdo Wig](https://learn.adafruit.com/glowing-beehive-hairdo-wig.md)
- [Circuit Playground Seashell Pendant](https://learn.adafruit.com/circuit-playground-seashell-pendant.md)
