超音波センサー

Dependencies:   mbed HCSR04

Files at this revision

API Documentation at this revision

Comitter:
shina
Date:
Wed Dec 25 06:21:20 2019 +0000
Commit message:
HC-SR04

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Wed Dec 25 06:21:20 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/2019NHK_teamA/code/HCSR04/#095071ae3cac
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 25 06:21:20 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file