Skip to content

Instantly share code, notes, and snippets.

@rakasaka
Created September 6, 2011 23:18
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 rakasaka/1199279 to your computer and use it in GitHub Desktop.
Save rakasaka/1199279 to your computer and use it in GitHub Desktop.
Arduino piano stair Processing script
import processing.serial.*;
import ddf.minim.signals.*; // Minim sound library
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
int prevent = 0; // Double ring prevention
Serial myPort; // The serial port
Minim minim;
AudioPlayer a;
AudioPlayer b;
AudioPlayer c;
void setup() {
// List all the available serial ports:
println(Serial.list());
minim = new Minim(this);
int prevent = 0;
a = minim.loadFile("15.mp3"); // Stair 15
b = minim.loadFile("14.mp3"); // Stair 14
c = minim.loadFile("13.mp3"); // Stair 13
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
}
void draw() {
while (myPort.available () > 0) {
String inBuffer = myPort.readStringUntil('\n');
if (inBuffer != null) {
if (inBuffer.contains("#0#") && prevent != 0) {
a.rewind();
a.play();
prevent = 0;
}
if (inBuffer.contains("#1#") && prevent != 1) {
b.rewind();
b.play();
prevent = 1;
}
if (inBuffer.contains("#2#") && prevent != 2) {
c.rewind();
c.play();
prevent = 2;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment