Stitch Pixels and Code

Add a chain of NeoPixels to GEMMA's GND, D1, and Vout pads. Any NeoPixels will work just fine (strips, sticks, rings, etc.) but in keeping with the textile theme of this project, we'll be using individual sewable pixels.

Start by stitching between GEMMA D1 and the data input of your first pixel. Knot the thread at each and and seal/snip.

Stitch very long strands of conductive thread to GEMMA GND and Vout and stitch each up to - and + on the first pixel. Knot the threads at the pixel but do not seal or cut the leads short. Instead wrap the excess threads around bobbins or scraps of paper to keep them out of the way.

Stop stitching after each pixel to test your stitched connections.

Upload the code below to GEMMA to see the interactive color changing effect using the soft potentiometer. This sketch doesn't do any smoothing of the sensor value before directly mapping it to a color, so the LEDs will flash different colors as you slide, then stay on a single color when you let go of the slide charm. We wanted to keep the code as simple as possible so you can learn exactly how the sensor works, so feel free to upgrade it to suit your project's needs!

#include <Adafruit_NeoPixel.h>

#define PIN 1
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

int sensorPin = 1;    // select the input pin for the potentiometer (analog 1 is digital 2)
int sensorValue = 0;  // variable to store the value coming from the sensor
int colorValue = 0;

void setup() {
  // Set internal pullup resistor for sensor pin (analog 1 is digital 2)
  pinMode(2, INPUT_PULLUP); 
  strip.begin();
  strip.setBrightness(40); //adjust brightness here
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  colorValue = map(sensorValue, 0, 1024, 0, 255); //map sensor values from 0-124 to 0-255
  for (int i = 0; i<strip.numPixels(); i++){
    strip.setPixelColor(i, Wheel(colorValue)); //use Wheel function to set color
  }
  strip.show();                
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Eight pixels stitched around the inside of the hood:

Last updated on 2015-11-23 at 04.59.54 PM Published on 2015-02-11 at 11.31.44 AM