/** * Simple Read * * Read data from the serial port and change the color of a rectangle * when a switch connected to a Wiring or Arduino board is pressed and released. * This example works with the Wiring / Arduino program that follows below. */ import ddf.minim.*; //create audio channel here (start with one) import processing.serial.*; AudioPlayer player1, player2, player3, player4; Serial port; int val; String tag = ""; String tag1 = "0F0302A98D\n"; String tag2 = "0415ED88A7\n"; String tag3 = "04162B79C2\n"; String tag4 = "04162C6FFD\n"; void setup() { size(1074, 800); frameRate(60); Minim.start(this); // load a file, give the AudioPlayer buffers that are 512 samples long player1 = Minim.loadFile("01.wav", 3000); player2 = Minim.loadFile("02.wav", 3000); player3 = Minim.loadFile("03.wav", 3000); player4 = Minim.loadFile("04.wav", 3000); port = new Serial(this, "/dev/ttyUSB0", 115200); // Load the font. Fonts are located within the // main Processing directory/folder and they // must be placed within the data directory // of your sketch for them to load PFont fontA = loadFont("Ziggurat-HTF-Black-32.vlw"); // Set the font and its size (in units of pixels) textFont(fontA, 32); } void draw() { if (0 < port.available()) { // If data is available, val = port.read(); // read it and store it in val switch(val) { case 240: tag = ""; break; case 247: println(tag); if (tag.equals(tag1) == true){ player2.pause(); player3.pause(); player4.pause(); player1.play(); int x = 30; // Use fill() to change the value or color of the text background(255, 204, 0); fill(0); text("male", x, 60); fill(51); text(">50 >57", x, 95); fill(0); text("bicycle", x, 130); fill(255); text("browser = Firefox", x, 165); fill(0); text("ip address = 192.178.0.6", x, 200); fill(51); text("provider = bru-net", x, 235); fill(0); text("hi, Frank", x, 270); fill(255); text("hates sports on television", x, 305); fill(0); text("likes to visit ceramics exhibitions", x, 340); fill(51); text("buys 5 Italian crime novels a year", x, 375); } if (tag.equals(tag2) == true){ player1.pause(); player3.pause(); player4.pause(); player2.play(); int x = 30; // Use fill() to change the value or color of the text background(255, 204, 0); fill(0); text("female", x, 60); fill(51); text("<18", x, 95); fill(0); text("has a library card", x, 130); fill(255); text("is not Belgian", x, 165); fill(0); text("is a member of the scouts", x, 200); fill(51); text("likes fuschia", x, 235); fill(0); text("likes Stereolab", x, 270); fill(255); text("has one brother", x, 305); fill(0); text("has bought a polaroid camera on February the 29th", x, 340); fill(51); text("will graduate in 2008 at Sint-Lukas", x, 375); } if (tag.equals(tag3) == true){ player1.pause(); player2.pause(); player4.pause(); player3.play(); int x = 30; // Use fill() to change the value or color of the text background(255, 204, 0); fill(0); text("gender neutral", x, 60); fill(51); text(">25 <30", x, 95); fill(0); text("organic", x, 130); fill(255); text("bicycle", x, 165); fill(0); text("likes metal", x, 200); fill(51); text("mac", x, 235); fill(0); text("ip address = 180.167.0.8", x, 270); fill(255); text("browser: Camino", x, 305); fill(0); text("visits http://www.cuteoverload.com three times a day", x, 340); fill(51); text("pays 536,98 Euro per month in the supermarket", x, 375); } if (tag.equals(tag4) == true){ player1.pause(); player3.pause(); player2.pause(); player4.play(); int x = 30; // Use fill() to change the value or color of the text background(255, 204, 0); fill(0); text("female", x, 60); fill(51); text(">25", x, 95); fill(0); text("likes shopping", x, 130); fill(255); text("car", x, 165); fill(0); text("4x4", x, 200); fill(51); text("home owner", x, 235); fill(0); text("steady job", x, 270); fill(255); text("has hypertension", x, 305); fill(0); text("buys luxury garden sets through e-bay", x, 340); fill(51); text("spends 217,53 Euro per month on manicures", x, 375); } break; default: tag += (char)val; } } } //background(0); //stroke(255); // draw the waveforms // the values returned by left.get() and right.get() will be between -1 and 1, // so we need to scale them up to see the waveform // note that if the file is MONO, left.get() and right.get() will return the same value for(int i = 0; i < player.left.size()-1; i++) { line(i, 50 + player.left.get(i)*50, i+1, 50 + player.left.get(i+1)*50); line(i, 150 + player.right.get(i)*50, i+1, 150 + player.right.get(i+1)*50); } } } /* // Wiring / Arduino Code // Code for sensing a switch status and writing the value to the serial port. int switchPin = 4; // Switch connected to pin 4 void setup() { pinMode(switchPin, INPUT); // Set pin 0 as an input Serial.begin(9600); // Start serial communication at 9600 bps } void loop() { if (digitalRead(switchPin) == HIGH) { // If switch is ON, Serial.print(1, BYTE); // send 1 to Processing } else { // If the switch is not ON, Serial.print(0, BYTE); // send 0 to Processing } delay(100); // Wait 100 milliseconds } */