Final Costume: Distance to Light

Final Costume

The Costume now consists of a big hoodie, an exaggerated back and shoulder part, Neopixel strips (two on each shoulder, one on the bag and one inside the hoodie) and an ultrasonic sensor in the back. As somebody approaches, more and more Neopixels on the strips  will light up, until all strips are fully light, when somebody stands directly behind the dancer.

 

Franzi

 

We used the following code and circuit:

Code:


// Needed Adafruit library to work with NeoPixels and definition of all
// the pins that are currently used
#include
#define Trigger_1 8
#define Echo_1 9
#define PIN_10 10
#define PIN_11 11
#define PIN_12 12
#define PIN_13 13
#define N1_LEDS 13
#define N2_LEDS 19
#define N3_LEDS 28


// Definition on each NeoPixel strip, with the number of LEDs on the strip,
// the pin where is is located on the Lilypad and the type of the strip
Adafruit_NeoPixel back_strip = Adafruit_NeoPixel(N2_LEDS, PIN_10, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel outer_shoulder_strip = Adafruit_NeoPixel(N2_LEDS, PIN_11, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel inner_shoulder_strip = Adafruit_NeoPixel(N1_LEDS, PIN_12, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel head_strip = Adafruit_NeoPixel(N3_LEDS, PIN_13, NEO_RGBW + NEO_KHZ800);


long duration_1, distance_1, distance;
int minRange, maxRange;


void setup() {
Serial.begin (9600);
pinMode(Trigger_1, OUTPUT);
pinMode(Echo_1, INPUT);


minRange = 0;
maxRange = 100;


// Initialization of the strips. This is needed, otherwise the Neopixel LEDs won’t light up
back_strip.begin();
inner_shoulder_strip.begin();
outer_shoulder_strip.begin();
head_strip.begin();
back_strip.show();
inner_shoulder_strip.show();
outer_shoulder_strip.show();
head_strip.show();
}


void loop() {
// Setup to calculate the distance with the distance sensor, where the trigger sends
// a signal and the echo recieves it and then calculates the duration
digitalWrite(Trigger_1, LOW);
delayMicroseconds(2);
digitalWrite(Trigger_1, HIGH);
delayMicroseconds(10);
digitalWrite(Trigger_1, LOW);
duration_1 = pulseIn(Echo_1, HIGH);


// Calculate the distance (in cm) based on the speed of sound.
distance_1 = duration_1/58.2;
Serial.println(distance_1);


// If someone is inside a range of 100cm behind the person then this if-cause will trigger
if ((minRange <= distance_1 <= maxRange) ) { distance = distance_1; Serial.println(distance); // The map function rewrites each distance(0-100) to a pixel(0-18) which is then used in a // for-loop to light up the pixels up to needed point for(int i = 18; i>= map(distance, 0, 100,0,18 ); i--)
{
// setPixelColor always lights on pixel up with a certain color declared after the pixel
back_strip.setPixelColor(i, 0,150,210);
outer_shoulder_strip.setPixelColor(i, 0,150,210);
inner_shoulder_strip.setPixelColor(i-6, 0,150,210);
head_strip.setPixelColor(map(i, 18, 0, 13, 0),150,0,210);
head_strip.setPixelColor(map(i, 18, 0, 14, 27),150,0,210);
back_strip.show();
outer_shoulder_strip.show();
inner_shoulder_strip.show();
head_strip.show();
}
for(int j = 0; j < map(distance, 0, 100, 0,18); j++) { back_strip.setPixelColor(j,0); outer_shoulder_strip.setPixelColor(j, 0); inner_shoulder_strip.setPixelColor(j-6, 0); head_strip.setPixelColor(33-j,0); head_strip.setPixelColor(-6+j,0); back_strip.show(); outer_shoulder_strip.show(); inner_shoulder_strip.show(); head_strip.show(); } // Function that was used while exhibiting the costume to have a constant lit up pixel // running through the costume to attract visitors /*} if (distance_1 > maxRange) {
for (int k=0; k <= 9; k++) {


outer_shoulder_strip.setPixelColor(k+10, 0,150,210); //10 -> 19
outer_shoulder_strip.setPixelColor(k, 0,150,210); // 0 -> 9


inner_shoulder_strip.setPixelColor(k+9, 0,150,210); // 9 -> 18
inner_shoulder_strip.setPixelColor(k-1, 0,150,210); // -1 -> 8


outer_shoulder_strip.setPixelColor(k+19, 0);
outer_shoulder_strip.setPixelColor(k+9, 0);
outer_shoulder_strip.setPixelColor(k-1, 0);


inner_shoulder_strip.setPixelColor(k+8, 0);
inner_shoulder_strip.setPixelColor(k-2, 0);


head_strip.setPixelColor(13,0);
head_strip.setPixelColor(14,0);
outer_shoulder_strip.show();
inner_shoulder_strip.show();
delay(100);
}
}*/
}
}

 

Circuit:

Bildschirmfoto 2016-05-30 um 22.58.02