// This program takes ASCII-encoded strings // from the serial port at 9600 baud and graphs them. It expects values in the // range 0 to 1023, followed by a newline, or newline and carriage return // Created 20 Apr 2005 // Updated 24 Nov 2015 // by Tom Igoe // This example code is in the public domain. import processing.serial.*; import ddf.minim.*; Minim minim; AudioPlayer player; AudioPlayer player2; AudioPlayer player3; AudioPlayer player4; AudioPlayer siren; AudioSample hat; AudioSample kick; AudioSample snare; AudioSample ahorn; Serial myPort; // The serial port int xPos = 1; // horizontal position of the graph float inByte = 0; String mine; float vol = 2; String cp; float gain2 = 0; float gain3 = 0; float gain4 = 0; void setup () { // set the window size: size(400, 300); minim = new Minim(this); player = minim.loadFile("genie.mp3"); player2 = minim.loadFile("connersong.mp3"); player3 = minim.loadFile("imagine.mp3"); // player4 = minim.loadFile("imagine.mp3"); siren = minim.loadFile("siren.mp3"); //currplay = minim.loadFile(cp); kick = minim.loadSample( "BD.mp3", // filename 512 // buffer size ); snare = minim.loadSample("SD.wav", 512); hat = minim.loadSample("CHH.wav", 512); ahorn = minim.loadSample("horn.mp3", 512); // List all the available serial ports // if using Processing 2.1 or later, use Serial.printArray() println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Arduino, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); // don't generate a serialEvent() unless you get a newline character: myPort.bufferUntil('\n'); // set inital background: background(0); } void draw () { String inString = myPort.readStringUntil('\n'); if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to an int and map to the screen height: inByte = float(inString); println(inByte); //inByte = map(inByte, 0, 1023, 0, 100); // draw the line: ellipse(60,20,100,100); float gain = map(inByte,0,255,-10.0,10.0); //GAIN WITH POT // float gain = map(inByte,0,15,-10.0,10.0); // GAIN WITH Sonic if("v1up".equals(inString)){ gain3 = gain3+6; } if("v1dn".equals(inString)){ gain3 = gain3-6; } if("b6".equals(inString)){ gain2 = gain2+5; } if("b7".equals(inString)){ gain2 = gain2-5; } if("v4up".equals(inString)){ gain4 = gain4+5; } if("v4dn".equals(inString)){ gain4 = gain4-5; } println("arduinoValue: " + inByte + " gain: " + gain); player.setGain(gain4); player2.setGain(gain2); player3.setGain(gain3); if ("b10".equals(inString)) { fill(255,200,200); player.play(); } if ("b10n".equals(inString)) { fill(155,100,200); player.pause(); } if ("b11".equals(inString)) { fill(255,45,200); player2.play(); } if ("b11n".equals(inString)) { fill(155,100,200); player2.pause(); } if ("b12".equals(inString)) { fill(155,100,200); player3.play(); // cp = ("melody.mp3"); } if ("b12n".equals(inString)) { fill(155,100,200); player3.pause(); } /* if ("b4".equals(inString)) { fill(155,100,200); player4.play(); // cp = ("dimond.mp3"); } if ("b4n".equals(inString)) { fill(155,100,200); player4.pause(); } */ /*if("kick".equals(inString)){ kick.trigger(); } if("snare".equals(inString)){ snare.trigger(); } if("hat".equals(inString)){ //hat.trigger(); siren.play(); } */ /* if("b10n".equals(inString)){ ahorn.trigger(); }*/ /* if("for".equals(inString)){ player2.skip(2000); } if("rev".equals(inString)){ player2.skip(-2000); } if("hold".equals(inString)){ player.pause(); } */ } }