First Distance sensor attempt

Dependencies:   mbed

Fork of frdm_Distance by Flying Monkeys

Files at this revision

API Documentation at this revision

Comitter:
danderson8814
Date:
Sat Jun 27 23:58:32 2015 +0000
Parent:
6:71c9054f905e
Commit message:
Attempt 871

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Jun 27 23:51:34 2015 +0000
+++ b/main.cpp	Sat Jun 27 23:58:32 2015 +0000
@@ -11,36 +11,23 @@
 InterruptIn sw2(SW2);
 Serial      pc(USBTX, USBRX);
 Timer       timer;
-long ReEnd;
+int ReEnd;
 
 void sw2_release(void)
 {
-        Trig = 0;
-        timer.reset();
-        wait_us(2);
-        led_red = 0;
-        led_green = 1;
-        Trig = 1;
-        wait_us(15);
-        Trig = 0;
-        while (!Re) {
-            timer.start();
-        }
-        
-        while (Re){
-            timer.stop();
-        }
-        
-    
-        ReEnd = timer.read_us();
-        pc.printf("Distance is %d cm \r\n" , ReEnd ); 
+     led_red = 0 ;
+     led_green = 1;
+     timer.reset();
     
 }
 
 void sw2_press(void)
 {
+    timer.stop();
+    ReEnd = timer.read_us();
     led_red = 1 ;
     led_green = 0;
+    pc.printf("Time between pushes %d us \r\n",ReEnd );
     
 }