The project is not done yet

Dependencies:   USBHost USBHostXpad mbed-rtos mbed

Fork of Totaleprogramma by jordy morsinkhof

ultrasoon.h

Committer:
347467
Date:
2015-02-25
Revision:
0:345f76c72b9a

File content as of revision 0:345f76c72b9a:

//#include "mbed.h"

I2C i2cMod(p28, p27);
//Serial PC(USBTX, USBRX);       //Debug port to PC

int i2cAddress1 = 0xF2;
int i2cAddress2 = 0xE0;

void sendStartRangingCommand1(void){
    const char command[] = {0x00, 0x51};
    i2cMod.write(i2cAddress1, command, 2);
}
void sendStartRangingCommand2(void){
    const char command[] = {0x00, 0x51};
    i2cMod.write(i2cAddress2, command, 2);
}
/* 
int readRange1(void){
    const char command[]  = {0x02};           //Address of range register
    char response[] = {0x00, 0x00};
    i2cMod.write(i2cAddress1, command, 1, 1);  //Send command
    i2cMod.read(i2cAddress1, response, 2);     //Read 16bits result
    int range = (response[0]<<8)+response[1]; //Shift two bytes into int   
    return range; 
}

int readRange2(void){
    const char command[]  = {0x02};           //Address of range register
    char response[] = {0x00, 0x00};
    i2cMod.write(i2cAddress2, command, 1, 1);  //Send command
    i2cMod.read(i2cAddress2, response, 2);     //Read 16bits result
    int range = (response[0]<<8)+response[1]; //Shift two bytes into int   
    return range; 
}

                    //void setAddress(int address) {
                     //Send address change sequence
                     //    char command[] = {0x00, 0xA0};
                    //   i2cMod.write(i2cAddress, command, 2);
                    //   command[1] = 0xAA;
                    //   i2cMod.write(i2cAddress, command, 2);
                     //   command[1] = 0xA5;
                     //   i2cMod.write(i2cAddress, command, 2);
                     //   command[1] = address;
                    //   i2cMod.write(i2cAddress, command, 2);
                    // }

    //int main() {
      //      //Read software version
    //const char command[]  = {0x00};           //Address of swversion register
    //char response[] = {0x00, 0x00};
    //i2cMod.write(i2cAddress1, command, 1, 1);  //Send command
    //i2cMod.read(i2cAddress1, response, 2);     //Read 16bits result
    //int swversion = (response[0]<<8)+response[1]; //Shift two bytes into int
    //PC.printf(" Software version1: %i", swversion);
    //PC.printf("\n\r");
    
                          //Read software version
                            //const char command[]  = {0x00};           //Address of swversion register
                            // char response[] = {0x00, 0x00};
                            // i2cMod.write(i2cAddress2, command, 1, 1);  //Send command
                            // i2cMod.read(i2cAddress2, response, 2);     //Read 16bits result
                            // int swversion = (response[0]<<8)+response[1]; //Shift two bytes into int
                            // PC.printf(" Software version2: %i", swversion);
                            // PC.printf("\n\r");
    
    
    //setAddress(0xF2) ;
        
    //while(true){
     //   sendStartRangingCommand1();
     //   wait(0.07);
     //   int range1 = readRange1();
     //   PC.printf(" Range1: %i", range1);
     //   PC.printf("\n\r");
     //   wait (0.2);
     
    // sendStartRangingCommand2();
    //    wait(0.07);
    //    int range2 = readRange2();
    //    PC.printf(" Range2: %i", range2);
    //    PC.printf("\n\r");
    //    wait(1.0);
     //}
//}