/**************************************************************************************************
*
*  Supersonic SRF05 - Module
*
*   Version:      1.0.0 - January 2009
*   Author:       Etienne Ribeiro    / tutorial assistant caad      /  eribeiro[at]ethz.ch
*   Supervisor:   Christoph Wartmann / chair for caad - ETH Zürich  /  wartmann[at].arch.ethz.ch
*
*   Desc:         This Module can be used to plug severel Supersonic SRF05 Sensors to your
*                 project. Connect your sensors to any digital pin on your board.
*
*   Methode:      int SRF05_getDistance (int digitalPin)
*                   digitalPin: Pin where your Supersonic Sensor is connected.
*                 void SRF05_getDistanceInCM (int digitalPin, int *ret1, int *ret2)
*                   digitalPin: Pin where your Supersonic Sensor is connected.
*                   *ret1: Return Value (upper). Access this value by &var
*                   *ret2: Return Value (lower). Access this value by &var
*                 void SRF05_toCM (int imp, int *ret1, int *ret2)
*                   imp: impules you mesured with SRF05_getDistance
*                   *ret1: Return Value (upper). Access this value by &var
*                   *ret2: Return Value (lower). Access this value by &var
*
***************************************************************************************************/



//
// Functions

int SRF05_getDistance (int digitalPin) {

        // Trigger pulse
        pinMode(digitalPin, OUTPUT);
        digitalWrite(digitalPin, LOW);
        delayMicroseconds(2);
        digitalWrite(digitalPin, HIGH);
        delayMicroseconds(10);
        digitalWrite(digitalPin, LOW);


        // Mesure echo pulse
        pinMode(digitalPin, INPUT);
        return pulseIn(digitalPin, HIGH); //, 1000);

}



void SRF05_getDistanceInCM (int digitalPin, int *ret1, int *ret2) {


        int val = SRF05_getDistance (digitalPin);
        SRF05_toCM (val, ret1, ret2);

}


void SRF05_toCM (int imp, int *ret1, int *ret2) {

        *ret1 = imp / 58;
        *ret2 = imp % 58 * 100 / 58;

}

This website has been archived and is no longer maintained.