JJ Dekker / Mbed 2 deprecated Totaleprogramma1

Dependencies:   USBHost USBHostXpad mbed-rtos mbed

Fork of Totaleprogramma by jordy morsinkhof

Revision:
0:345f76c72b9a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ultrasoon.h	Wed Feb 25 08:25:16 2015 +0000
@@ -0,0 +1,85 @@
+//#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);
+     //}
+//}
\ No newline at end of file