Controlando som de Minim pela duas LDRs no Arduino (analog entrada 0 e 1)
void setup() { Serial.begin(9600); } void loop() { Serial.print(analogRead(0)); Serial.print(","); Serial.println(analogRead(1)); }
import ddf.minim.*; import ddf.minim.ugens.*; import processing.serial.*; import ddf.minim.effects.*; int x, y; Minim minim; AudioOutput out; Oscil osc; IIRFilter filt; Serial myPort; // Create object from Serial class StringBuffer serialBytes = new StringBuffer(); // used decoding number coming via Serial connection int serialTimer; // Used to test a time-out of input data coming in Serial connection color col; void setup() { size(500,500); x = 200; y = 250; String ports [] = Serial.list(); println(ports); String portName = ports[ports.length-1]; myPort = new Serial(this, portName, 9600); myPort.bufferUntil(10); minim = new Minim(this); out = minim.getLineOut(); osc = new Oscil( 440, 0.5f, Waves.SAW ); filt = new BandPass(880, 20, out.sampleRate()); //filt = new NotchFilter(440, 20, out.sampleRate()); osc.patch(filt).patch(out); } static int bufferSize = 10; String getSerialLine(Serial port) { int lf = 10; String lfs = Character.toString((char)lf); byte[] inBuffer = new byte[bufferSize]; port.readBytesUntil(lf, inBuffer); for (int i=0;i<bufferSize;i++) { print( "("+inBuffer[i]+") "); } println(); String s = new String(inBuffer); s = s.split(lfs)[0]; s = s.replace("\n","").replace("\r","").replace(" ",""); println(s); return s; } void draw() { background(0); fill(100,200,255); ellipse(x,y,50,50); osc.setFrequency( 1500 - (y * 3) ); filt.setFreq(500 - (x*4)); } void mouseClicked() { y = mouseY; } void serialEvent(Serial p) { String s = p.readString(); s = s.replace("\n","").replace("\r","").replace(" ",""); if (s.length() > 1) { println("***"+s+"+++" + s.length() + " :"); String[] vals =s.split(","); int l1 =(int)(Integer.parseInt(vals[0])); y=(int)map(l1,50,300,0,500); int l2 =(int)(Integer.parseInt(vals[1])); x=(int)map(l2,50,300,0,500); } }