If a skirt doesn't appeal to you, use this circuit and code on a hat, a belt buckle, and even a blinky dog collar.
Prerequisite guides:
Text editor powered by tinymce.
Text editor powered by tinymce.
Text editor powered by tinymce.
Text editor powered by tinymce.
Text editor powered by tinymce.
Double check that all your conductive thread tails have been trimmed and your skirt is laying flat on a nonconductive surface, and then connect your FLORA main board to your computer with a USB cable.
Open the Adafruit Arduino IDE, which you can download from the Getting Started with FLORA guide.
You will need the NeoPixel library for this project-- if you've never installed an Arduino library before, read our guide on the topic!
Open up the Library manager
Find the Adafruit NeoPixel library and install it...
First test out all six pixels by uploading the sketch in File >> Examples >> Adafruit_NeoPixel >> strandtest.
If all of your pixels light up and change color, you're good to continue to the back! Disconnect the USB cable before stitching more pixels on the back. For more tips on stitching up a line of NeoPixels, read the corresponding page in our LED Ampli-Tie guide.
When you have pixels on the front and back of the skirt, place a piece of scrap fabric in between them for testing (so they don't short each other out), or put the skirt on a dress form. When you're wearing the skirt, your body will keep the front and back from touching.
Next test out the accelerometer, install the Adafruit LSM303DLHC library using the library manager. Make sure you grab the one with DLHC in the name
Also, install the Adafruit Unified Sensor library
Now test by uploading the sketch in File >> Examples >> Adafruit_LSM303 >> Accel_Sensor.
Open up the serial monitor and watch for changing motion values. For more information, check out our FLORA Accelerometer guide.
Click the Download File button below to get the code.
The colors can be specified in the myFavoriteColors
array, and the sensitivity to motion can be defined with MOVE_THRESHOLD
.
// SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_LSM303DLH_Mag.h> #include <Adafruit_NeoPixel.h> // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_RGB Pixels are wired for RGB bitstream // NEO_GRB Pixels are wired for GRB bitstream // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, 6, NEO_GRB + NEO_KHZ800); Adafruit_LSM303DLH_Mag_Unified accel = Adafruit_LSM303DLH_Mag_Unified(54321); // Here is where you can put in your favorite colors that will appear! // just add new {nnn, nnn, nnn}, lines. They will be picked out randomly // R G B uint8_t myFavoriteColors[][3] = {{200, 0, 200}, // purple {200, 0, 0}, // red {200, 200, 200}, // white }; // don't edit the line below #define FAVCOLORS sizeof(myFavoriteColors) / 3 // mess with this number to adjust TWINklitude :) // lower number = more sensitive #define MOVE_THRESHOLD 45 void setup() { Serial.begin(9600); // Try to initialise and warn if we couldn't detect the chip if (!accel.begin()) { Serial.println("Oops ... unable to initialize the LSM303. Check your wiring!"); while (1); } strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { /* Get a new sensor event */ sensors_event_t event; accel.getEvent(&event); Serial.print("Accel X: "); Serial.print(event.acceleration.x); Serial.print(" "); Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" "); Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" "); // Get the magnitude (length) of the 3 axis vector // http://en.wikipedia.org/wiki/Euclidean_vector#Length double storedVector = event.acceleration.x*event.acceleration.x; storedVector += event.acceleration.y*event.acceleration.y; storedVector += event.acceleration.z*event.acceleration.z; storedVector = sqrt(storedVector); Serial.print("Len: "); Serial.println(storedVector); // wait a bit delay(100); // get new data! accel.getEvent(&event); double newVector = event.acceleration.x*event.acceleration.x; newVector += event.acceleration.y*event.acceleration.y; newVector += event.acceleration.z*event.acceleration.z; newVector = sqrt(newVector); Serial.print("New Len: "); Serial.println(newVector); // are we moving if (abs(newVector - storedVector) > MOVE_THRESHOLD) { Serial.println("Twinkle!"); flashRandom(5, 1); // first number is 'wait' delay, shorter num == shorter twinkle flashRandom(5, 3); // second number is how many neopixels to simultaneously light up flashRandom(5, 2); } } void flashRandom(int wait, uint8_t howmany) { for(uint16_t i=0; i<howmany; i++) { // pick a random favorite color! int c = random(FAVCOLORS); int red = myFavoriteColors[c][0]; int green = myFavoriteColors[c][1]; int blue = myFavoriteColors[c][2]; // get a random pixel from the list int j = random(strip.numPixels()); //Serial.print("Lighting up "); Serial.println(j); // now we will 'fade' it in 5 steps for (int x=0; x < 5; x++) { int r = red * (x+1); r /= 5; int g = green * (x+1); g /= 5; int b = blue * (x+1); b /= 5; strip.setPixelColor(j, strip.Color(r, g, b)); strip.show(); delay(wait); } // & fade out in 5 steps for (int x=5; x >= 0; x--) { int r = red * x; r /= 5; int g = green * x; g /= 5; int b = blue * x; b /= 5; strip.setPixelColor(j, strip.Color(r, g, b)); strip.show(); delay(wait); } } // LEDs will be off when done (they are faded to 0) }
// SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_LSM303DLH_Mag.h> #include <Adafruit_NeoPixel.h> // Parameter 1 = number of pixels in strip // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_RGB Pixels are wired for RGB bitstream // NEO_GRB Pixels are wired for GRB bitstream // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, 6, NEO_GRB + NEO_KHZ800); Adafruit_LSM303DLH_Mag_Unified accel = Adafruit_LSM303DLH_Mag_Unified(54321); // Here is where you can put in your favorite colors that will appear! // just add new {nnn, nnn, nnn}, lines. They will be picked out randomly // R G B uint8_t myFavoriteColors[][3] = {{200, 0, 200}, // purple {200, 0, 0}, // red {200, 200, 200}, // white }; // don't edit the line below #define FAVCOLORS sizeof(myFavoriteColors) / 3 // mess with this number to adjust TWINklitude :) // lower number = more sensitive #define MOVE_THRESHOLD 45 void setup() { Serial.begin(9600); // Try to initialise and warn if we couldn't detect the chip if (!accel.begin()) { Serial.println("Oops ... unable to initialize the LSM303. Check your wiring!"); while (1); } strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { /* Get a new sensor event */ sensors_event_t event; accel.getEvent(&event); Serial.print("Accel X: "); Serial.print(event.acceleration.x); Serial.print(" "); Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" "); Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" "); // Get the magnitude (length) of the 3 axis vector // http://en.wikipedia.org/wiki/Euclidean_vector#Length double storedVector = event.acceleration.x*event.acceleration.x; storedVector += event.acceleration.y*event.acceleration.y; storedVector += event.acceleration.z*event.acceleration.z; storedVector = sqrt(storedVector); Serial.print("Len: "); Serial.println(storedVector); // wait a bit delay(100); // get new data! accel.getEvent(&event); double newVector = event.acceleration.x*event.acceleration.x; newVector += event.acceleration.y*event.acceleration.y; newVector += event.acceleration.z*event.acceleration.z; newVector = sqrt(newVector); Serial.print("New Len: "); Serial.println(newVector); // are we moving if (abs(newVector - storedVector) > MOVE_THRESHOLD) { Serial.println("Twinkle!"); flashRandom(5, 1); // first number is 'wait' delay, shorter num == shorter twinkle flashRandom(5, 3); // second number is how many neopixels to simultaneously light up flashRandom(5, 2); } } void flashRandom(int wait, uint8_t howmany) { for(uint16_t i=0; i<howmany; i++) { // pick a random favorite color! int c = random(FAVCOLORS); int red = myFavoriteColors[c][0]; int green = myFavoriteColors[c][1]; int blue = myFavoriteColors[c][2]; // get a random pixel from the list int j = random(strip.numPixels()); //Serial.print("Lighting up "); Serial.println(j); // now we will 'fade' it in 5 steps for (int x=0; x < 5; x++) { int r = red * (x+1); r /= 5; int g = green * (x+1); g /= 5; int b = blue * (x+1); b /= 5; strip.setPixelColor(j, strip.Color(r, g, b)); strip.show(); delay(wait); } // & fade out in 5 steps for (int x=5; x >= 0; x--) { int r = red * x; r /= 5; int g = green * x; g /= 5; int b = blue * x; b /= 5; strip.setPixelColor(j, strip.Color(r, g, b)); strip.show(); delay(wait); } } // LEDs will be off when done (they are faded to 0) }
Text editor powered by tinymce.
Text editor powered by tinymce.