DOCUMENTATION OF USER INTERACTION
VIDEO OF ARTWORK'S USE
Arduino Code for Lights #include <Wire.h> #include "Adafruit_MPR121.h" #ifndef _BV #define _BV(bit) (1 << (bit)) #endif // You can have up to 4 on one i2c bus but one is enough for testing! Adafruit_MPR121 cap = Adafruit_MPR121(); // Keeps track of the last pins touched // so we know when buttons are 'released' uint16_t lasttouched = 0; uint16_t currtouched = 0; int led1 = 9; // the PWM pin the LED is attached to int led2 = 10; int led3 = 11; int brightness = 0; // how bright the LED is int fadeAmount = 10; // how many points to fade the LED b int led13 = 13; // the pin the LED is connected to int led12 = 12; int led7 = 7; int led001 = 6.; int led5 = 5; int led4 = 4; int led003 = 3; int led002 = 2; int led8 = 8; void setup() { Serial.begin(9600); while (!Serial) { // needed to keep leonardo/micro from starting too fast! delay(10); } Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); // Default address is 0x5A, if tied to 3.3V its 0x5B // If tied to SDA its 0x5C and if SCL then 0x5D if (!cap.begin(0x5A)) { Serial.println("MPR121 not found, check wiring?"); while (1); } Serial.println("MPR121 found!"); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led13, OUTPUT); // Declare the LED as an output pinMode(led12, OUTPUT); // Declare the LED as an output pinMode(led7, OUTPUT); // Declare the LED as an output pinMode(led001, OUTPUT); // Declare the LED as an output pinMode(led5, OUTPUT); // Declare the LED as an output pinMode(led4, OUTPUT); // Declare the LED as an output pinMode(led003, OUTPUT); // Declare the LED as an output pinMode(led002, OUTPUT); // Declare the LED as an output pinMode(led8, OUTPUT); // Declare the LED as an output } void loop() { // Get the currently touched pads currtouched = cap.touched(); int range = cap.touched(); switch (range) { case 0: if ((! (cap.touched() & (1 << 1)) ) && (! (cap.touched() & (1 << 6) ) && (! (cap.touched() & (1 << 11)) ))) Serial.write(0); break; case 1: if ((cap.touched() & (1 << 1)) && (cap.touched() & (1 << 6)) && (cap.touched() & (1 << 11))) Serial.write(1); break;} for (uint8_t i=0; i<12; i++) { // it if is touched and wasnt touched before, alert! if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { Serial.print(i); Serial.println(" touched"); } // if it was touched and now isnt, alert! if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { Serial.print(i); Serial.println(" released"); } } ///// 1=led 1 6=led2 11=led3 //////////// /// no lanterns touched, everything on if ((! (cap.touched() & (1 << 1)) ) && (! (cap.touched() & (1 << 6) ) && (! (cap.touched() & (1 << 11)) ))) { analogWrite(led1,50); analogWrite(led2,50); analogWrite(led3,50); digitalWrite(led13, HIGH); // Turn the LED on digitalWrite(led12, HIGH); // Turn the LED on digitalWrite(led7, HIGH); // Turn the LED on digitalWrite(led001, HIGH); // Turn the LED on digitalWrite(led5, HIGH); // Turn the LED on digitalWrite(led4, HIGH); // Turn the LED on digitalWrite(led003, HIGH); // Turn the LED on digitalWrite(led002, HIGH); // Turn the LED on digitalWrite(led8, HIGH); // Turn the LED on } ////////// ///all lanterns touched, everything off if ((cap.touched() & (1 << 1)) && (cap.touched() & (1 << 6)) && (cap.touched() & (1 << 11))) { analogWrite(led1,0); analogWrite(led2,0); analogWrite(led3,0); digitalWrite(led13, LOW); // Turn the LED off digitalWrite(led12, LOW); // Turn the LED off digitalWrite(led7, LOW); // Turn the LED off digitalWrite(led001, LOW); // Turn the LED off digitalWrite(led5, LOW); // Turn the LED off digitalWrite(led4, LOW); // Turn the LED off digitalWrite(led003, LOW); // Turn the LED off digitalWrite(led002, LOW); // Turn the LED off digitalWrite(led8, LOW); // Turn the LED off } ////////// /// one lantern touched, one off, two on if ((cap.touched() & (1 << 1)) && (! (cap.touched() & (1 << 6) ) && (! (cap.touched() & (1 << 11) )))) { analogWrite(led1,0); analogWrite(led2,100); analogWrite(led3,100); digitalWrite(led13, LOW); // Turn the LED off digitalWrite(led12, LOW); // Turn the LED off digitalWrite(led7, LOW); // Turn the LED off digitalWrite(led001, HIGH); // Turn the LED on digitalWrite(led5, HIGH); // Turn the LED on digitalWrite(led4, HIGH); // Turn the LED on digitalWrite(led003, HIGH); // Turn the LED on digitalWrite(led002, HIGH); // Turn the LED on digitalWrite(led8, HIGH); // Turn the LED on } if ((cap.touched() & (1 << 6)) && (! (cap.touched() & (1 << 1) ) && (! (cap.touched() & (1 << 11) )))) { analogWrite(led1,100); analogWrite(led2,0); analogWrite(led3,100); digitalWrite(led13, HIGH); // Turn the LED on digitalWrite(led12, HIGH); // Turn the LED on digitalWrite(led7, HIGH); // Turn the LED on digitalWrite(led001, LOW); // Turn the LED off digitalWrite(led5, LOW); // Turn the LED off digitalWrite(led4, LOW); // Turn the LED off digitalWrite(led003, HIGH); // Turn the LED on digitalWrite(led002, HIGH); // Turn the LED on digitalWrite(led8, HIGH); // Turn the LED on } if ((cap.touched() & (1 << 11)) && (! (cap.touched() & (1 << 6) ) && (! (cap.touched() & (1 << 1) )))) { analogWrite(led1,100); analogWrite(led2,100); analogWrite(led3,0); digitalWrite(led13, HIGH); // Turn the LED on digitalWrite(led12, HIGH); // Turn the LED on digitalWrite(led7, HIGH); // Turn the LED on digitalWrite(led001, HIGH); // Turn the LED on digitalWrite(led5, HIGH); // Turn the LED on digitalWrite(led4, HIGH); // Turn the LED on digitalWrite(led003, LOW); // Turn the LED off digitalWrite(led002, LOW); // Turn the LED off digitalWrite(led8, LOW); // Turn the LED off } ////////////////////// ///two lanterns touched, two off, one on if (cap.touched() & (1 << 1) && cap.touched() & (1 << 6) && (! (cap.touched() & (1 << 11) ))) { analogWrite(led1,0); analogWrite(led2,0); analogWrite(led3,255); digitalWrite(led13, LOW); // Turn the LED off digitalWrite(led12, LOW); // Turn the LED off digitalWrite(led7, LOW); // Turn the LED off digitalWrite(led001, LOW); // Turn the LED off digitalWrite(led5, LOW); // Turn the LED off digitalWrite(led4, LOW); // Turn the LED off digitalWrite(led003, HIGH); // Turn the LED on digitalWrite(led002, HIGH); // Turn the LED on digitalWrite(led8, HIGH); // Turn the LED on } if (cap.touched() & (1 << 1) && cap.touched() & (1 << 11) && (! (cap.touched() & (1 << 6) ))) { analogWrite(led1,0); analogWrite(led2,255); analogWrite(led3,0); digitalWrite(led13, LOW); // Turn the LED off digitalWrite(led12, LOW); // Turn the LED off digitalWrite(led7, LOW); // Turn the LED off digitalWrite(led001, HIGH); // Turn the LED on digitalWrite(led5, HIGH); // Turn the LED on digitalWrite(led4, HIGH); // Turn the LED on digitalWrite(led003, LOW); // Turn the LED off digitalWrite(led002, LOW); // Turn the LED off digitalWrite(led8, LOW); // Turn the LED off } if (cap.touched() & (1 << 6) && cap.touched() & (1 << 11) && (! (cap.touched() & (1 << 1) ))) { analogWrite(led1,255); analogWrite(led2,0); analogWrite(led3,0); digitalWrite(led13, HIGH); // Turn the LED on digitalWrite(led12, HIGH); // Turn the LED on digitalWrite(led7, HIGH); // Turn the LED on digitalWrite(led001, LOW); // Turn the LED off digitalWrite(led5, LOW); // Turn the LED off digitalWrite(led4, LOW); // Turn the LED off digitalWrite(led003, LOW); // Turn the LED off digitalWrite(led002, LOW); // Turn the LED off digitalWrite(led8, LOW); // Turn the LED off } // reset our state lasttouched = currtouched; // comment out this line for detailed data from the sensor! return; // debugging info, what Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX); Serial.print("Filt: "); for (uint8_t i=0; i<12; i++) { Serial.print(cap.filteredData(i)); Serial.print("\t"); } Serial.println(); Serial.print("Base: "); for (uint8_t i=0; i<12; i++) { Serial.print(cap.baselineData(i)); Serial.print("\t"); } Serial.println(); // put a delay so it isn't overwhelming delay(100); }
Processing Code for sound /** * This sketch demonstrates how to play a file with Minim using an AudioPlayer. <br /> * It's also a good example of how to draw the waveform of the audio. Full documentation * for AudioPlayer can be found at http://code.compartmental.net/minim/audioplayer_class_audioplayer.html * <p> * For more information about Minim and additional features, * visit http://code.compartmental.net/minim/ */ import processing.serial.*; import ddf.minim.*; Minim minim; AudioPlayer player; Serial myPort; int val; void setup() { size(512, 200, P3D); // we pass this to Minim so that it can load files from the data directory minim = new Minim(this); // I know that the first port in the serial list on my mac // is Serial.list()[0]. // On Windows machines, this generally opens COM1. // Open whatever port is the one you're using. String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port print(portName); myPort = new Serial(this, portName, 9600); // loadFile will look in all the same places as loadImage does. // this means you can find files that are in the data folder and the // sketch folder. you can also pass an absolute path, or a URL. player = minim.loadFile("space.mp3"); //convert to mav. } void draw() { while ( myPort.available() > 0) { // If data is available, val = myPort.read(); // read it and store it in val } println(val); //print it out in the console background(255); //stroke(255); switch (val) { case 10: fill(0); player.pause(); break; case 0: fill(255); player.play(); break;} for(int i = 0; i < player.bufferSize() - 1; i++) { float x1 = map( i, 0, player.bufferSize(), 0, width ); float x2 = map( i+1, 0, player.bufferSize(), 0, width ); line( x1, 50 + player.left.get(i)*50, x2, 50 + player.left.get(i+1)*50 ); line( x1, 150 + player.right.get(i)*50, x2, 150 + player.right.get(i+1)*50 ); } // draw a line to show where in the song playback is currently located float posx = map(player.position(), 0, player.length(), 0, width); stroke(0,200,0); line(posx, 0, posx, height); if ( player.isPlaying() ) { text("Press any key to pause playback.", 10, 20 ); } else { text("Press any key to start playback.", 10, 20 ); } } void keyPressed() { if ( player.isPlaying() ) { player.pause(); } // if the player is at the end of the file, // we have to rewind it before telling it to play again else if ( player.position() == player.length() ) { player.rewind(); player.play(); } else { player.play(); } }