Controlando som de Minim pela duas LDRs no Arduino (analog entrada 0 e 1)
=== Arduino ===
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print(analogRead(0));
Serial.print(",");
Serial.println(analogRead(1));
}
=== Processing ===
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 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);
}
}