Skip to content

Instantly share code, notes, and snippets.

@victordiaz
Created August 14, 2014 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victordiaz/257985b52e6081bf735e to your computer and use it in GitHub Desktop.
Save victordiaz/257985b52e6081bf735e to your computer and use it in GitHub Desktop.
conductive_thread_processing
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.ugens.*;
//serial for arduino
Serial myPort;
//audio
Minim minim;
AudioOutput out;
Oscil wave;
void setup() {
size(200, 200);
//depending on the arduino the number has to be changed
String portName = Serial.list()[5];
println(Serial.list());
myPort = new Serial(this, portName, 9600);
//audio
minim = new Minim(this);
out = minim.getLineOut();
wave = new Oscil( 440, 0.5f, Waves.SINE );
wave.patch( out );
wave.setWaveform( Waves.SAW );
wave.setAmplitude( 2 );
}
float myVal = 0;
float cleanVal = 0;
void draw() {
if ( myPort.available() > 0) {
//get line from arduino
String arduinoString = myPort.readStringUntil('\n');
//check if its valid
if (arduinoString != null && arduinoString != "") {
//transform it into a number
myVal = (float)parseInt(arduinoString.trim());
//map it to the variables I want
cleanVal = map(myVal, 600, 1000, 0, 255);
println("cleanVal " + cleanVal);
}
}
//change bg
background(cleanVal);
//set sound frequency
wave.setFrequency( cleanVal * 1.5 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment