D:/DRISSI/arduino-0022/arduino-0022/libraries/uSonic/uSonic1.cpp
00001 //Usonic.cpp
00002 
00003 #include <uSonic1.h>
00004 
00005 
00006 
00007 
00008 byte highByte = 0x00;                             // Stores high byte from ranging
00009 byte lowByte = 0x00;                              // Stored low byte from ranging
00010 
00011 
00012 
00013 
00014 int getRange(){                                   // This function gets a ranging from the SRF10
00015   
00016   int range = 0; 
00017   
00018   Wire.beginTransmission(srfAddress);             // Start communticating with SRF10
00019   Wire.send(cmdByte);                             // Send Command Byte
00020   Wire.send(0x51);                                // Send 0x51 to start a ranging
00021   Wire.endTransmission();
00022   
00023   delay(100);                                     // Wait for ranging to be complete
00024   
00025   Wire.beginTransmission(srfAddress);             // start communicating with SRFmodule
00026   Wire.send(rangeByte);                           // Call the register for start of ranging data
00027   Wire.endTransmission();
00028   
00029   Wire.requestFrom(srfAddress, 2);                // Request 2 bytes from SRF module
00030   while(Wire.available() < 2);                    // Wait for data to arrive
00031   highByte = Wire.receive();                      // Get high byte
00032   lowByte = Wire.receive();                       // Get low byte
00033 
00034   range = (highByte << 8) + lowByte;              // Put them together
00035    
00036   return(range);  // Returns Range
00037 
00038 }
00039 
00040 int getRangee(){                                   // This function gets a ranging from the SRF10
00041   
00042   int range = 0; 
00043   
00044   Wire.beginTransmission(srAddress);             // Start communticating with SRF10
00045   Wire.send(cmdByte);                             // Send Command Byte
00046   Wire.send(0x51);                                // Send 0x51 to start a ranging
00047   Wire.endTransmission();
00048   
00049   delay(100);                                     // Wait for ranging to be complete
00050   
00051   Wire.beginTransmission(srAddress);             // start communicating with SRFmodule
00052   Wire.send(rangeByte);                           // Call the register for start of ranging data
00053   Wire.endTransmission();
00054   
00055   Wire.requestFrom(srAddress, 2);                // Request 2 bytes from SRF module
00056   while(Wire.available() < 2);                    // Wait for data to arrive
00057   highByte = Wire.receive();                      // Get high byte
00058   lowByte = Wire.receive();                       // Get low byte
00059 
00060   range = (highByte << 8) + lowByte;              // Put them together
00061    
00062   return(range);  // Returns Range
00063 
00064 }
00065 
00066 
00067 
00068 
00069