超音波センサー

Dependencies:   mbed HCSR04

Revision:
0:69ac1abc8193
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 25 06:21:20 2019 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+#include "hcsr04.h"
+
+Serial pc(USBTX,USBRX);
+DigitalOut led(LED1);
+HCSR04 usensor(D4,D6);
+
+unsigned int dist;
+
+int main(){
+    usensor.set_temperature(15);
+    while(true){
+        usensor.start();
+        wait_ms(100);
+        dist=usensor.get_dist_cm();
+        pc.printf("%dmm\n",dist*10);
+        if(dist<100){
+            led=1;
+            }else{
+                led=0;
+                }
+        }
+        }
+    
+    
\ No newline at end of file