/* * Skirt Full of Stars * * Uses a LilyPad Arduino and accelerometer to control the color of RGB LEDs * Which are sewn into the waistband of a skirt with fiber optics * Tutorial available at http://StarSkirt.PolymathDesignLab.com * * Designed by Shannon Henry, Polymath Design Lab */ int sensorValueX; //variables to hold accelerometer data int sensorValueY; int sensorValueZ; int acceleroX = 0; //analogue petal that accelerometer X coord reading is tied to int acceleroY = 1; //analogue petal that accelerometer Y coord reading is tied to int acceleroZ = 2; //analogue petal that accelerometer Z coord reading is tied to int adjustedX; //variables to hold remapped values for color generation int adjustedY; int adjustedZ; int redTab = 4; //petal attached to red LED lead int blueTab = 2; //petal attached to blue LED lead int greenTab = 3; //petal attached to green LED lead void initializeRGB(void) { pinMode(redTab, OUTPUT); pinMode(blueTab, OUTPUT); pinMode(greenTab, OUTPUT); analogWrite(redTab, 0); analogWrite(blueTab, 0); analogWrite(greenTab, 0); } void setup() { Serial.begin(9600); //initialize the serial port so that you can communicate with the computer } void loop() { sensorValueX = analogRead(acceleroX); // read accelerometer data sensorValueY = analogRead(acceleroY); sensorValueZ = analogRead(acceleroZ); adjustedX = map(sensorValueX, 400, 650, 0, 255); //maps the sensor value onto the range 1-255 to correspond with color values adjustedY = map(sensorValueY, 400, 600, 0, 255); //To calibrate - uncomment serial.println code below, and adjustedZ = map(sensorValueZ, 430, 650, 0, 255); //adjust initial 2 values to reflect range of readings received when calibrating //Serial.println(adjustedX); // send the sensor data to the computer so you can calibrate RGB LED display //Serial.println(adjustedY); // //Serial.println(adjustedZ); // //Serial.println(); // comment out the Serial.println lines again once color calibration is complete delay(5); // very brief delay analogWrite(redTab, adjustedX); // display the color analogWrite(blueTab, adjustedY); analogWrite(greenTab, adjustedZ); }