teensyduino and Ultrasonic RangeFinder

Hi, I am working on a project including the teensyduino and the LV-MaxSonar-EZ0 Ultrasonic Range Finder
I am trying to get the teensyduino to output a tone that changes in pitch depending on what distance the rangefinder is detecting

here is the arduino code:

//#include <math.h>


int VIBRATION_PIN = 19;
int SOUNDOUT_PIN = 17;
int INPUT_PIN = 18;
int VIBRATE = 0, SOUND = 1, CURRENT_MODE = 0;
double scaleFactor;
unsigned long duration, value;
long inputVal;  //pwm value from the rangefinder 
int x = 1;
long FLOOR, CEILING, DIST;
int TONE_CEILING = 400;
int count = 0, ceiling = 1000;

void setup(){
  pinMode( INPUT_PIN, INPUT);
  digitalWrite( INPUT_PIN, HIGH); // turn on internal pullup, pin will be HIGH unless connected to GND by switch
  
  scaleFactor = 0;  //ratio comprised of rangefinder input value over max rangefinder value, applied to max output(audio or vibration) to get output value
  //setMode( SOUND );  //just do this for now until we get vibration working
  //Serial.begin( 9600 );
  FLOOR = 300;
  CEILING = 10,000;
  DIST = CEILING - FLOOR;
  Serial.println( "Done" );
}

//main loop
void loop(){
  //pinMode( INPUT_PIN, INPUT );
  //duration = pulseIn( INPUT_PIN, HIGH );
  //duration = microsecondsToInches( duration );
  //Serial.println( duration );
    count++;
    if( count > ceiling ){
      duration = ping();
      count = 0;
    }
   
    
  //send feedback in appropriate mode  
  //if( CURRENT_MODE == SOUND){
    pinMode( SOUNDOUT_PIN, OUTPUT );
    writeTone( duration );
  //}
}

unsigned long ping(){
  /*pinMode( INPUT_PIN, OUTPUT );
  digitalWrite( INPUT_PIN, LOW );
  delayMicroseconds( 2 );
  digitalWrite( INPUT_PIN, HIGH );
  delayMicroseconds( 5 );
  digitalWrite( INPUT_PIN, LOW );*/
  
  pinMode( INPUT_PIN, INPUT );
  //digitalWrite( INPUT_PIN, HIGH );
  
//calculate a ratio from the found range/max range and apply it to the max tone to calculate the tone to output
duration = pulseIn( INPUT_PIN, HIGH );
  scaleFactor = ( DIST - duration ) / DIST;
  inputVal = scaleFactor * TONE_CEILING;
   //Serial.println( (int)value );
  return inputVal;
}

//send tone signal
void writeTone( int freq ){
  digitalWrite( SOUNDOUT_PIN, HIGH );
  delayMicroseconds( freq );
  
  digitalWrite( SOUNDOUT_PIN, LOW );
  delayMicroseconds( freq );
}

though the arduino does output a tone, it is a very low tone and does not change with the rangefinder whatsoever.

we have tested the rangefinder with a multimeter and the voltage changed as we moved our hand farther and closer, so we know the rangefinder is working. We also called writeTone( 200 ) and a high-pitched tone came out, so we know that that works correctly. We have checked the pin connections and they correspond correctly with the pin variables we have defined.

what are we doing wrong?

edit: sorry for not posting this in interfacing

You might try removing the comma from this line.

CEILING = 10,000;

This actually causes CEILING to be set to 10, not 10000. That's probably not what you intended.

You might also try adding a Serial.println(duration) immediately after you call pulseIn() and watch the numbers in the serial monitor.

thanks, its still not working but that's at least one problem solved
how do I get the serial to print? I have teensy selected as the board in arduino 0013, and I can compile the .hex with it and then open it with the teensy loader, is there something else I should be doing?
Thanks

how do I get the serial to print?

In the setup section, add Serial.begin(9600). You already have this, just uncomment it. Add the Serial.println(duration) right after the line with pulseIn.

When your sketch is running, select the serial port using the Tools -> Serial Port menu, and then click on the "Serial Monitor" button.

If you're using Linux, make sure you added the udev rule described in "Additional Installation Steps" on this page:

http://www.pjrc.com/teensy/td_download.html

OK, I got the serial working

as a test, I changed the code in the main loop to this:

 //pinMode( INPUT_PIN, INPUT );
  //duration = pulseIn( INPUT_PIN, HIGH );
  //duration = microsecondsToInches( duration );

    Serial.println( "16" );
    //count++;
    //if( count > ceiling ){
      //duration = ping();
      //count = 0;
        
    //}
    
    //Serial.println( "16" );


  //send feedback in appropriate mode
  //if( CURRENT_MODE == SOUND){
    pinMode( SOUNDOUT_PIN, OUTPUT );
    writeTone( duration );

If I do this, it repeatedly prints sixteen as it should
However, if I uncomment duration = ping(); nothing will print, not even one "16"

could ping() be freezing it?

You can use Serial.println() almost anywhere, including inside your ping() function.... such as immediately after the call to pulseIn() as I'd suggested.

More likely than not, it's getting stuck inside pulseIn().

Are you certain you really do have pulses arriving at that pin?

is there any way to check if the pin is getting pulses? We checked the rangefinder's analog out with a multimeter and its working, is there a possibility that the pwm is not?