Arduino / Ping / Sine Wave

Hi!

I'm totally new to arduino and processing, but i'm slowing getting a grasp on some of the language. What I'm looking to do is control this program for a sine wave signal (below) with the PING motion sensor.

Here is the code for the sine wave, which is currently controlled by a mouse -

import ddf.minim.;
import ddf.minim.signals.
;

Minim minim;
AudioOutput out;
SineWave sine;

void setup()
{
size(512, 200, P2D);

minim = new Minim(this);
// get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
out = minim.getLineOut(Minim.STEREO);
// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
sine = new SineWave(440, 0.5, 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);
}

void draw()
{
background(0);
stroke(255);
// 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 mouseMoved()
{
// with portamento on the frequency will change smoothly
float freq = map(mouseY, 0, height, 1500, 60);
sine.setFreq(freq);
// pan always changes smoothly to avoid crackles getting into the signal
// note that we could call setPan on out, instead of on sine
// this would sound the same, but the waveforms in out would not reflect the panning
float pan = map(mouseX, 0, width, -1, 1);
sine.setPan(pan);
}

void stop()
{
out.close();
minim.stop();

super.stop();
}

Can anyone provide some help with this? Would greatly appreciate any guidance.

This is the Ping Code -

const int pingPin = 7;

void setup() {
// initialize serial communication:
Serial.begin(9600);
}

void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();

delay(100);
}

long microsecondsToInches(long microseconds)
{

You're missing the body of "microsecondsToInches".

control this program for a sine wave signal (below) with the PING motion sensor

Isn't very clear - what is it you want to do?

I'm basically looking to make a theremin. In the sine program, when the mouse is at the bottom of the window, the wave is wide and the sound is low. At the top, the wave is tighter and the sound high. I want to program it so when the ping reads a certain distance, say 3 inches, the frequency is high. 4 inches, slightly lower, 5 inches, slightly lower, 6 inches slightly lower, ect.

This is for an art installation in which someone will be wearing a suit with several ping sensors on it, connected to an arduino, connected to a rotating speaker mounted on a helmet.

So instead of the sine wave program reading the position of a mouse, I'd like it to read the ping sensor.

the rest of the PING code -

long microsecondsToInches(long microseconds)
{

// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}

finally finished with some other projects, looking to get back to work on this one.

any suggestions?

basically i want it to play a low tone when distance = x, a high tone when distance = y, ect.

So, how far did you get?
Can you post your current code?

(please don't cross-post)