Justin Kaput's log

Final

posted Aug 26, 2010, 8:59 PM by Unknown user   [ updated Aug 30, 2010, 7:11 PM ]

So I've written the codes in Arduino and Processing for my drum glove to work. I made the glove out of 1/2 inch pipe insulator foam with a push button inserted into each of the 4 chunks of foam, one for each of the 4 fingers on one hand. I decided against making one for the thumb because it was too awkward to play it at the angle I needed to mount the push button at. I know using push buttons isn't the greatest way of building the glove, but it works the same as if they were pressure sensors. I haven't taught myself a song with it yet, but with enough time playing with it and it shouldn't be too long. Here are the codes:
 
Arduino:
 
int pushPin1 = 2;      // denote which push pins are connected to which pins on the Arduino board
int pushPin2 = 3;
int pushPin3 = 4;
int pushPin4 = 5;
int val;                // set up the variables
int val2;
int val3;
int val4;
void setup() {
  Serial.begin(9600);          // begin serial communication at 9600 bps
  pinMode(pushPin1, INPUT);    // set the pins on the Arduino board to input
  pinMode(pushPin2, INPUT);
  pinMode(pushPin3, INPUT);
  pinMode(pushPin4, INPUT);
}
void loop() {
  val = digitalRead(pushPin1);        // read the value, store it in the variable
  val2 = digitalRead(pushPin2);
  val3 = digitalRead(pushPin3);
  val4 = digitalRead(pushPin4);
  if(val == HIGH) {                    // if the value is high,
    Serial.print(val, DEC);            // print the value to the serial port as a decimal (will be a 1 for high)
    Serial.print("\t");                // and separate this value from the next with a tab
  }
  if(val == LOW) {                     // if the value is low,
    Serial.print(val, DEC);            // print the value to the serial port as a decimal (will be a 0 for low);
    Serial.print("\t");                // and separate this value from the next with a tab
  }
  if(val2 == HIGH) {
    Serial.print(val2, DEC);
    Serial.print("\t");
  }
  if(val2 == LOW) {
    Serial.print(val2, DEC);
    Serial.print("\t");
  }
  if(val3 == HIGH) {
    Serial.print(val3, DEC);
    Serial.print("\t");
  }
  if(val3 == LOW) {
    Serial.print(val3, DEC);
    Serial.print("\t");
  }
  if(val4 == HIGH) {
    Serial.println(val4, DEC);
  }
  if(val4 == LOW) {
    Serial.println(val4, DEC);
  }
  delay(100);                            // delay 100 milliseconds before reading the values again
}
 
 
Processing:
 
import processing.serial.*;      // import serial library
import ddf.minim.*;              // import minim sound library
Serial myPort;                   // this next block of code just sets up the variables
AudioSample bass;
AudioSample snare;
AudioSample hiHat;
AudioSample cowbell;
Minim minim;
int fillBass;
int fillSnare;
int fillCymbalR;
int fillCymbalG;
int fillCowbellR;
int fillCowbellG;
void setup() {
  size(400, 400);                      // sets the screen size
  myPort = new Serial(this, Serial.list()[0], 9600);      // tells the program to start paying attention to the serial port
  myPort.bufferUntil('\n');                               // store the data from the serial port until the value is reached
  minim = new Minim(this);                                // begins the minim sound library
  bass = minim.loadSample("Bass2.wav", 2048);             // loads the audio samples
  snare = minim.loadSample("Snare.wav", 2048);
  hiHat = minim.loadSample("Hi_Hat.wav", 2048);
  cowbell = minim.loadSample("Cowbell.wav", 2048);
  background(0);                                          // sets the background color
  fillBass = 255;                                         // these are used later to help distinguish when an element of the drum set is being played
  fillSnare = 255;
  fillCymbalR = 230;
  fillCymbalG = 161;
  fillCowbellR = 153;
  fillCowbellG = 77;
}
void draw() {
  stroke(0);                                            // set the stroke color
  fill(fillBass);                                       // set the fill color. I used a variable so the color could change when a button is pressed
  ellipse(width/2, 3*height/4, 150, 150);               // draw the bass drum
  fill(255);
  rect(163, 3*height/8, 75, 30);                       
  fill(fillSnare);
  ellipse(width/2, 3*height/8, 75, 50);                 // draw the snare drum
  fill(fillCymbalR, fillCymbalG, 0);
  ellipse(width/4, height/4, 75, 25);                   // draw the cymbal
  fill(fillCowbellR, fillCowbellG, 0);
  stroke(fillCowbellR+10, fillCowbellG+10, 0);          // I made the cowbell look 3-D just for kicks and giggles
  rect(3*width/4, height/4, 30, 20);                    // draw the cowbell
  quad(3*width/4, height/4, 320, 75, 340, 75, 330, 100);
  quad(330, 100, 340, 75, 340, 85, 330, 120);
  fill(0);
  rect(305, 104, 20, 12);
}
void serialEvent(Serial myPort) {                            // when data is being received from the serial port, proceed with this function
  String myString = myPort.readStringUntil('\n');            // read the data from the serial port until the value is reached
  print (myString);                                          // print the data being received
  if (myString != null) {                                    // if there is data
    String myString1 = trim(myString);                       // cut out any whitespace
    println(myString1);                                      // print the data again to ensure it hasn't changed
    int buttons[] = int(split(myString1, '\t'));             // split the string of numbers at the tabs so they can be distinguished from each other
    for (int buttonNum = 0; buttonNum < 4; buttonNum++) {    // create 4 new variables (buttons[0-3]
      println("Button " + buttonNum + ": " + buttons[buttonNum]); // print the new variables and their values
    }
    println();                                                // add a line after to separate old data from new incoming data. It just makes it easier on the eyes
    if(buttons[0] == 0) {                                    // if this button is pressed,
        bass = minim.loadSample("Bass2.wav", 2048);          // load this audio sample
        bass.trigger();                                      // and play it
        fillBass = 150;                                      // change the fill color of the element of the drum set
        delay(100);                                          // delay so the color change is noticeable and the sound doesn't repeat too rapidly
        fillBass = 255;                                      // reset the fill color
    }
    if(buttons[1] == 0) {
      snare = minim.loadSample("Snare.wav", 2048);
      snare.trigger();
      fillSnare = 150;
      delay(100);
      fillSnare = 255;
    }
    if(buttons[2] == 0) {
      hiHat = minim.loadSample("Hi_Hat.wav", 2048);
      hiHat.trigger();
      fillCymbalR = 255;                                       // I used 2 different variables here to denote the element's red and green fill amounts
      fillCymbalG = 179;
      delay(100);
      fillCymbalR = 230;
      fillCymbalG = 161;
    }
    if(buttons[3] == 0) {
      cowbell = minim.loadSample("Cowbell.wav", 2048);
      cowbell.trigger();
      fillCowbellR = 179;
      fillCowbellG = 89;
      delay(100);
      fillCowbellR = 153;
      fillCowbellG = 77;
    }
  }
}
void stop() {                // when the window is closed,
  bass.close();              // close the audio samples
  snare.close();
  hiHat.close();
  cowbell.close();
  minim.stop();              // and stop minim
  super.stop();
}
 
 
Here are some pics of the glove setup and a short video of the program working is attached.
 
 
So I realize this isn't exactly the same as the Megatap 3000, but it works in the same fashion. If I had time to order the force sensitive resistors online I would have, but these push buttons were the best alternative I could find.

Final Project Idea - Drum Gloves

posted Aug 19, 2010, 10:24 AM by Unknown user

    My mom sent me this link (http://www.chris3000.com/portfolio/megatap-3000/) to a website that has plans for MegaTap 3000, which is a set of drum gloves that use pressure sensors on the fingertips to play drum sounds. My idea would be to create my own drum gloves and have them play a set of drums in a processing sketch. I would use different fingers as different elements of the drum kit, and could possibly (no promises) play part of a song when it's all finished. I think this would be really cool to play with and could be elaborated later into possibly guitar and/or bass gloves. I would try to make them now, but I don't think I can teach myself guitar and have it ready to go in a week.

Assignment 11.2

posted Aug 16, 2010, 8:09 PM by Unknown user

This one isn't very exciting, but I figured I'd better turn it in and get started on my final. It turns two motors one way when the cursor is on the white rectangle in the processing window and the other way when the cursor is on the red rectangle. Here are my codes:
 
Arduino:
 
int val;                          // set up variables
const int motor1Pin1 = 4;
const int motor1Pin2 = 3;
const int motor2Pin1 = 5;
const int motor2Pin2 = 6;
const int enable1Pin = 8;
const int enable2Pin = 9;
 
void setup() {
  pinMode(motor1Pin1, OUTPUT);      // set motor pins to output
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);
  pinMode(enable2Pin, OUTPUT);
  digitalWrite(enable1Pin, HIGH);    // set enable pins to high
  digitalWrite(enable2Pin, HIGH);
  Serial.begin(9600);                // begin serial communication at 9600 bps
}
void loop() {
  if(Serial.available()) {      // if data is available,
    val = Serial.read();        // read it and store it in val
  }
  if (val == 1) {                  // if val is this,
    digitalWrite(motor1Pin1, HIGH);    // turn the motors one way
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  }
  if (val == 2) {                  // if val is this,
    digitalWrite(motor1Pin1, LOW);    // turn the motors the other way
    digitalWrite(motor1Pin2, HIGH);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  }
}
 
Processing:
 
import processing.serial.*;  //import the processing serial library
Serial myPort;            // set up variables
int val;
void setup() {
  size(200, 200);      // set screen size
  myPort = new Serial(this, Serial.list()[0], 9600);    // begin serial communication at 9600 bps
  background(0);      // set background color
}
void draw() {
  val = mouseX;          // set val equal to the mouse position in the x plain
  if(val <= 100) {    // if val is less than or equal to 100,
    myPort.write(1);  // write 1 to the serial port
    println(1);       // and print 1
  }
  if(val >= 101) {    // if val is greater than or equal to 101,
    myPort.write(2);  // write 2 to the serial port
    println(2);       // and print 2
  }
  stroke(255);        // set stroke color
  fill(255);          // set fill color
  rect(0, 0, width/2, height);    // draw a rectangle equal to half the window
  fill(225, 0, 0);
  stroke(225, 0, 0);
  rect(width/2, 0, width, height);
}
 
and here's a Fritzing pic of my circuit:
 

Assignment 11.1

posted Aug 8, 2010, 4:13 PM by Unknown user

So I took an old toy:
 
and took it apart like so:
 
so I could get these:
 
in order to do this:

Assignment 10.3

posted Aug 4, 2010, 1:25 PM by Unknown user   [ updated Aug 5, 2010, 11:48 AM ]

I used keys on the keyboard to light up the RGB LED different colors when different keys are pressed. The keys used are "r" for the red LED, "g" for the green LED, "b" for the blue LED, and "y", "c", "m", and "w" to light up combinations of the three LEDs to produce yellow, cyan, magenta, and white, respectively. When the key is pressed in the Processing window, the background color is changed also. Here are my codes:
 
Arduino
 
int red = 11;      // set up variables
int green = 3;
int blue = 9;
int val;
void setup() {
  Serial.begin(9600);    // begin serial communication at 9600 bps
}
void loop() {
  if (Serial.available()) {    // if serial is available,
    val = Serial.read();       // read it and store it in val
  }
  if (val == 'r') {            // if val is this,
    analogWrite(red, 255);     // light up this LED and
    delay(25);                 // delay for 25 millisceonds
  }
  else if (val == 'g') {
    analogWrite(green, 255);
    delay(25);
  }
  else if (val == 'b') {
    analogWrite(blue, 255);
    delay(25);
  }
  else if (val == 'y') {
    analogWrite(red, 255);
    analogWrite(green, 255);
    delay(25);
  }
  else if (val == 'c') {
    analogWrite(green, 255);
    analogWrite(blue, 255);
    delay(25);
  }
  else if (val == 'm') {
    analogWrite(red, 255);
    analogWrite(blue, 255);
    delay(25);
  }
  else if (val == 'w') {
    analogWrite(red, 255);
    analogWrite(green, 255);
    analogWrite(blue, 255);
    delay(25);
  }
  else if (val == 'n') {
    analogWrite(red, 0);
    analogWrite(green, 0);
    analogWrite(blue, 0);
  }
}
 
Processing
 
import processing.serial.*;    // import processing serial library
Serial myPort;                 // set up variable

void setup() {
size(250, 250);        // sets screen size to 250 x 250 pixels
myPort = new Serial(this, Serial.list()[0], 9600);    // sets up serial port and begins serial communication at 9600 bps
}
void draw() {
    background(0);         // sets background color to black
}
void keyPressed() {
  if (key == 'r') {        // if key pressed is this key:
    myPort.write('r');     // write r to the serial port,
    background(255, 0, 0); // change the background color, and
    delay(15);             // delay for 15 milliseconds
  }
  if (key == 'g') {
    myPort.write('g');
    background(0, 255, 0);
    delay(15);
  }
  if (key == 'b') {
    myPort.write('b');
    background(0, 0, 255);
    delay(15);
  }
  if (key == 'y') {
    myPort.write('y');
    background(255, 255, 0);
    delay(15);
  }
  if (key == 'c') {
    myPort.write('c');
    background(0, 255, 255);
    delay(15);
  }
  if (key == 'm') {
    myPort.write('m');
    background(255, 0, 255);
    delay(15);
  }
  if (key == 'w') {
    myPort.write('w');
    background(255);
    delay(15);
  }
  if (key == 'x') {        // I have no idea why I need this, but
    myPort.write('n');     // if I don't have it the last color will
                           // stay on until the program is reset
  }                       
  else {                    // if any other key is pressed,
    myPort.write('n');      // write n to the serial port
  }
}
 
 
 
 
I tried to make it so that pressing a combination of keys would light up the same combination of LEDs, but it would either not turn off when the keys were released or would only light up one of the LEDs.

Assignment 10.2

posted Jul 30, 2010, 9:07 AM by Unknown user

For this sketch I used the X position of the cursor in the Processing window to control both the brightness of an LED connected to pin 9 of my Arduino and the opacity of a rectangle in the Processing window. Here are my codes:
Arduino:
 
int val = 0;
int ledPin = 9;
void setup() {
  Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
  val = Serial.read();
}
analogWrite(ledPin, val);
delay(20);
}
 
and Processing:
 
import processing.serial.*;
Serial myPort;
int valX;
int valY;
void setup() {
  size(255, 255);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}
void draw() {
  background(0);
  valX = mouseX;
  myPort.write(valX);
  println(valX);
  delay(20);
  fill(0, 255, 0, valX);
  rect(0, 0, 255, 255);
}
 
I tried to use the Y position of the cursor to control another LED, but I don't know how to split the String of values sent from Processing to Arduino.
 

Assignment 9.3

posted Jul 19, 2010, 7:42 PM by Unknown user

Here I made a program that plays different techno loops when different keys on the keyboard are pressed. The keys used are d, f, g, h, j, and k. The loops can be played all at once or one at a time.
 
Processing code:
 
import ddf.minim.*;      // include the minim library
AudioPlayer intro;       // declare variables
AudioPlayer stabs;
AudioPlayer layers;
AudioPlayer chords;
AudioPlayer aliens;
AudioPlayer playstation;
Minim minim;
void setup()
{
  // set screen size
  size(512, 200, P2D);
  minim = new Minim(this);
  // load a file, give the AudioPlayer buffers that are 2048 samples long
  intro = minim.loadFile("Trance_Intro.wav", 2048);
  stabs = minim.loadFile("Trance_Synth_Stabs.wav", 2048);
  layers = minim.loadFile("Trance_Layers_2.wav", 2048);
  chords = minim.loadFile("Rave_Chords.wav", 2048);
  aliens = minim.loadFile("Nine_Inch_Aliens.wav", 2048);
  playstation = minim.loadFile("Playstation.wav", 2048);
}
void draw()
{
  background(0);        // set background color
  stroke(255);          // set the stroke color
  // draw the waveforms
  // the values returned by left.get() and right.get() will be between -1 and 1,
  // so we need to scale them up to see the waveform
  for(int i = 0; i < intro.left.size()-1; i++)
  {
    stroke(0, i, 0);    // change each line's color to spice things up a bit
    line(i, 50 + intro.left.get(i)*50, i+1, 50 + intro.left.get(i+1)*50);
    line(i, 150 + intro.right.get(i)*50, i+1, 150 + intro.right.get(i+1)*50);
  }
  for(int u = 0; u < stabs.left.size()-1; u++)
  {
    stroke(u, 0, 0);
    line(u, 50 + stabs.left.get(u)*50, u+1, 50 + stabs.left.get(u+1)*50);
    line(u, 150 + stabs.right.get(u)*50, u+1, 150 + stabs.right.get(u+1)*50);
  }
  for(int y = 0; y < layers.left.size()-1; y++)
  {
    stroke(0, 0, y);
    line(y, 50 + layers.left.get(y)*50, y+1, 50 + layers.left.get(y+1)*50);
    line(y, 150 + layers.right.get(y)*50, y+1, 150 + layers.right.get(y+1)*50);
  }
  for(int t = 0; t < chords.left.size()-1; t++)
  {
    stroke(t, 0, t);
    line(t, 50 + chords.left.get(t)*50, t+1, 50 + chords.left.get(t+1)*50);
    line(t, 150 + chords.right.get(t)*50, t+1, 150 + chords.right.get(t+1)*50);
  }
  for(int r = 0; r < aliens.left.size()-1; r++)
  {
    stroke(0, r, r);
    line(r, 50 + aliens.left.get(r)*50, r+1, 50 + aliens.left.get(r+1)*50);
    line(r, 150 + aliens.right.get(r)*50, r+1, 150 + aliens.right.get(r+1)*50);
  }
  for(int e = 0; e < playstation.left.size()-1; e++)
  {
    stroke(e, e, 0);
    line(e, 50 + playstation.left.get(e)*50, e+1, 50 + playstation.left.get(e+1)*50);
    line(e, 150 + playstation.right.get(e)*50, e+1, 150 + playstation.right.get(e+1)*50);
  }
}
void keyPressed() {
  if(key == 'k') {                                     // if key pressed is this,
  intro = minim.loadFile("Trance_Intro.wav", 2048);    // reload the file and
  intro.play();                                        // play it
  }
  if(key == 'j') {
  stabs = minim.loadFile("Trance_Synth_Stabs.wav", 2048);
  stabs.play();
  }
  if(key == 'h') {
  layers = minim.loadFile("Trance_Layers_2.wav", 2048);
  layers.play();
  }
  if(key == 'g') {
  chords = minim.loadFile("Rave_Chords.wav", 2048);
  chords.play();
  }
  if(key == 'f') {
  aliens = minim.loadFile("Nine_Inch_Aliens.wav", 2048);
  aliens.play();
  }
  if(key == 'd') {
    // this one was taken from Eiffel 65's song "My Console" on their album Europop
  playstation = minim.loadFile("Playstation.wav", 2048);
  playstation.play();
  }
}
void stop()
{
  // always close Minim audio classes when you are done with them
  intro.close();
  stabs.close();
  layers.close();
  chords.close();
  aliens.close();
  minim.stop();
  super.stop();
}
 
I borrowed the playstation loop from one of my old CDs just for fun.

Assignment 10.1

posted Jul 16, 2010, 8:48 PM by Unknown user   [ updated Jul 30, 2010, 9:41 AM ]

For this one I used a potentiometer connected to analog pin 1 to control the brightness of an LED connected to digital pin 9.
Here's my code:
 
int val = 0;
int ledPin = 9;
int potPin = 1;
void setup() {
  //twiddle your thumbs
}
void loop() {
  val = analogRead(potPin);
  val = map(val, 0, 1023, 0, 225);
  analogWrite(ledPin, val);
  delay(30);
}
 
Here's a Fritzing pic of my circuit:
 
 
 

Assignment 9.2

posted Jul 16, 2010, 7:29 PM by Unknown user

This circuit uses four push buttons connected to pins 4-7 on the Arduino to control sound in Processing. For each button pressed, a different drum sound is played in Processing. For example: when the button connected to pin 4 is pressed, a cowbell sound is played. The sounds can also be played by pressing keys k, j, h, and g.
 
Arduino code:
 
int switchPin1 = 4;    // declares variables
int switchPin2 = 5;
int switchPin3 = 6;
int switchPin4 = 7;
void setup() {
  Serial.begin(9600);          // begin serial communication at 9600 bps
  pinMode(switchPin1, INPUT);  // set switchPins to input
  pinMode(switchPin2, INPUT);
  pinMode(switchPin3, INPUT);
  pinMode(switchPin4, INPUT);
}
void loop() {
  if(digitalRead(switchPin1) == HIGH) {    // if button is pressed
    Serial.print(1, DEC);                  // print this number
    delay(100);                            // and delay for 100 milliseconds
  }
  else if(digitalRead(switchPin2) == HIGH) {
    Serial.print(2, DEC);
    delay(100);
  }
  else if(digitalRead(switchPin3) == HIGH) {
    Serial.print(3, DEC);
    delay(100);
  }
  else if(digitalRead(switchPin4) == HIGH) {
    Serial.print(4, DEC);
    delay(100);
 
}
}
 
Processing code:
 
import processing.serial.*;      // import libraries
import ddf.minim.*;
Minim minim;                // declare variables
AudioSample cowbell;
AudioSample bass;
AudioSample kick;
AudioSample snare;
Serial myPort;
void setup()
{
  // sets screen size
  size(512, 200, P2D);
  // always start Minim before you do anything with it
  minim = new Minim(this);
  // load file from the data folder, with a 512 sample buffer
  cowbell = minim.loadSample("Cowbell.mp3");
  bass = minim.loadSample("Bass.wav");
  kick = minim.loadSample("Kick.wav");
  snare = minim.loadSample("Snare.wav");
  // sets port to read from
  String portName = Serial.list()[0];
  myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw()
{
  int val = 0;    // resets value every time draw is run
  background(0);  // sets background color
  stroke(255);    // sets stroke color
  // use the mix buffer to draw the waveforms.
  // because these are MONO files, we could have used the left or right buffers and got the same data
  for (int i = 0; i < cowbell.bufferSize() - 1; i++)
  {
    line(i, 100 - cowbell.left.get(i)*50, i+1, 100 - cowbell.left.get(i+1)*50);
  }
  for (int u = 0; u < bass.bufferSize() - 1; u++)
  {
    line(u, 100 - bass.left.get(u)*50, u+1, 100 - bass.left.get(u+1)*50);
  }
  for (int y = 0; y < kick.bufferSize() - 1; y++)
  {
    line(y, 100 - kick.left.get(y)*50, y+1, 100 - kick.left.get(y+1)*50);
  }
  for (int t = 0; t < snare.bufferSize() - 1; t++)
  {
    line(t, 100 - snare.left.get(t)*50, t+1, 100 - snare.left.get(t+1)*50);
  }
  if (myPort.available() > 0) {  // if there is data available to read,
    val = myPort.read();         // read it and store it in val
    println(val);                // print the value of val
  }
  if (val == 49 ) cowbell.trigger();    // if val is this, play the sound
  if (val == 50 ) bass.trigger();
  if (val == 51 ) kick.trigger();
  if (val == 52 ) snare.trigger();
}
void keyPressed()
{
  if ( key == 'k' ) cowbell.trigger();    // if this key is pressed, play this sound
  if ( key == 'j' ) bass.trigger();
  if ( key == 'h' ) kick.trigger();
  if ( key == 'g' ) snare.trigger();
}
void stop()
{
  // always close Minim audio classes when you are done with them
 
  cowbell.close();
  bass.close();
  kick.close();
  snare.close();
  minim.stop();
 
  super.stop();
}
 
This one took me a while to figure out. It took me a couple tries to figure out where exactly to save the sound clips so that they could be read in the program, and then when i got that worked out the sound would repeat until another button was pressed, and then that sound would repeat. I solved that by resetting val every time the void draw function was run. I still have no idea where the values change from 1-4 to 49-52, but I got the program working and I didn't want to mess it up. A Fritzing picture of my circuit is attached.

Assignment 9.1

posted Jul 15, 2010, 10:13 AM by Unknown user

I built a completely new circuit for this one. I got rid of the push buttons and added two potentiometers attached to analog pins 0 and 4 so that I could get two analog values to control the frequency(pitch) and amplitude(volume).
 
Arduino:
 
int potPin1 = 0;    // set up variables
int potPin2 = 4;
int val1 = 0;
int val2 = 0;
void setup() {
  Serial.begin(9600);    // begin serial communication at 9600 bps
}
void loop() {
  val1 = analogRead(potPin1);    // read potPin value and store in val1
  val1 = map(val1, 0, 1023, 0, 4978);    // adjust values
  val2 = analogRead(potPin2);
  val2 = map(val2, 0, 1023, 0, 4978);
  Serial.print(val1, DEC);      // print values and separate with a comma
  Serial.print(',');
  Serial.println(val2, DEC);
}
 
Processing:
 
import processing.serial.*;    //  import libraries
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;          // set up variables
AudioOutput out;
SineWave sine;
Serial myPort;
float freq;
float amp;
void setup() {
  size(400, 220, P2D);    // sets  window size
  minim = new Minim(this);
  // get a line out from Minim with default bufferSize, sample rate, and bit depth
  out = minim.getLineOut(Minim.STEREO);
  // create a sine wave oscillator, set to value of freq, value of amp, sample rate from line out
  sine = new SineWave(freq, amp, out.sampleRate());
  // set the portamento speed on the oscillator to 200 milliseconds
  sine.portamento(200);
  // add the oscillator to the line out
  out.addSignal(sine);
  // declares myPort and begins serial communication at 9600 bps
  myPort = new Serial(this, Serial.list()[0], 9600);
  // store values from myPort in a buffer until value is reached
  myPort.bufferUntil('\n');
 
}
void draw() {
  background(0);    // sets background color
  stroke(255);      // sets stroke color
  // draw the waveforms
  for(int i = 0; i < out.bufferSize() - 1; i++)
  {
    float x1 = map(i, 0, out.bufferSize(), 0, width);
    float x2 = map(i+1, 0, out.bufferSize(), 0, width);
    line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }
}
void serialEvent (Serial myPort) {
  // read string and store it in a buffer until value is reached
  String myString = myPort.readStringUntil('\n');
  // if there is something in myString
  if(myString != null) {
    // split it at the comma
    myString = trim(myString);
    int sensors[] = int(split(myString, ','));
    for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
      // print the sensor values
      print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
    }
    println();
    if(sensors.length > 1) {
      // adjust the value of sensors[0] and set as freq
      float freq = map(sensors[0], 0, 4978, 1500, 60);
      // set the frequency to the new values
      sine.setFreq(freq);
      // adjust the value of sensors[1] and set as amp
      float amp = map(sensors[1], 0, 4978, -1, 1);
      // set the amplitude to the new values
      sine.setAmp(amp);
     
    }
  }
  sine.setPan(0);    // set speaker balance to even
}
void stop() {
  out.close();
  minim.stop();
  super.stop();
}
 
A Fritzing picture of the circuit is attached.

1-10 of 39