Created libraries2

Dependencies:   mbed ultrasonic

Revision:
5:b2df25183cb1
Parent:
4:ae7f8a25c748
Child:
6:0d4008544238
--- a/main.cpp	Thu Apr 16 08:54:29 2015 +0000
+++ b/main.cpp	Thu Apr 16 10:50:23 2015 +0000
@@ -13,33 +13,38 @@
 void TX1_send(){
     HVoff = 0;
     //tresh = 1;
-    t1.reset();
     TX1.period(0.0000252);                  // Set the period of TX1 to 25.2us (39,682kHz)
     TX1.pulsewidth(0.0000116);              // Set the pulsewidth of TX1 to 11.6us (ON)
     wait(0.0002016);                        // Waits 201.6us
     TX1 = 0;
     //tresh =0;
+    t1.reset();
+    
     HVoff = 1;
     //pc.printf("It writes TX1\r\n");
-    to1.attach(TX1_send,0.01);              // Sends for 1000us
-    wait_ms(86);                            // Waits 86ms. Total 100ms
+    to1.attach(TX1_send,0.1);              // Sends for 1000us
+    //wait_ms(86);                            // Waits 86ms. Total 100ms
     }
 
 
 void signal_reciev(){
     
-    pc.printf("test1");
+    float time = t1.read();
+    float cm = 0;
+    
+    if (time<0.006 && time>0.0007){
     
-    float time = t1.read();
-    
-    pc.printf("%f/r/n", time);
-    
+        cm = 34613*time/2;                  // Calculate distance
+        
+        pc.printf("%f\r\n", cm);            // Prints distance
+        }
     }
 
 int main() {
+     
+    t1.start();
+    signal.fall(&signal_reciev);
     TX2 = 1;
-    TX1_send();
-    signal.rise(&signal_reciev);
-    //pc.printf("%f\r\n", volt.read());       // Function to write to serial chart 
+    TX1_send(); 
     while(1);
     }
\ No newline at end of file