Created
March 16, 2013 02:00
-
-
Save jvns/5174581 to your computer and use it in GitHub Desktop.
Processing program to play bytes from the serial port as music
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ddf.minim.*; | |
import ddf.minim.ugens.*; | |
import processing.serial.*; | |
Serial myPort; // The serial port | |
Minim minim; | |
AudioOutput out; | |
Oscil osc; | |
void setup() { | |
minim = new Minim( this ); | |
out = minim.getLineOut( Minim.MONO, 2048 ); | |
// osc = new Oscil( 400.23, 0.8 ); | |
// osc.patch( out ); | |
println(Serial.list()); | |
// Open the port you are using at the rate you want: | |
myPort = new Serial(this, Serial.list()[0], 19200); | |
out.setDurationFactor(0.2); | |
out.playNote( "EF3" ); | |
} | |
String notes[] = {"C4", "D4", "E4", "F4", "G4", "A4", "B4", "C5", "D5", "E5", "F5", "G5", "A5", "B5", "C6", "D6"}; | |
int lastNote = 0; | |
int inByte = 0; | |
void draw() { | |
int receivedByte = 0; | |
while (myPort.available() > 0) { | |
receivedByte = myPort.read(); | |
if (receivedByte != 0) { | |
inByte = receivedByte; | |
} | |
} | |
// osc.frequency.setLastValue( 200 + inByte ); | |
if ((millis() - lastNote) > 200) { | |
println(inByte); | |
println(notes[inByte/16]); | |
out.playNote(notes[inByte/16]); | |
lastNote = millis(); | |
} | |
//println(inByte); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment