超音波センサー

Dependencies:   mbed HCSR04

Committer:
shina
Date:
Wed Dec 25 06:21:20 2019 +0000
Revision:
0:69ac1abc8193
HC-SR04

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shina 0:69ac1abc8193 1 #include "mbed.h"
shina 0:69ac1abc8193 2 #include "hcsr04.h"
shina 0:69ac1abc8193 3
shina 0:69ac1abc8193 4 Serial pc(USBTX,USBRX);
shina 0:69ac1abc8193 5 DigitalOut led(LED1);
shina 0:69ac1abc8193 6 HCSR04 usensor(D4,D6);
shina 0:69ac1abc8193 7
shina 0:69ac1abc8193 8 unsigned int dist;
shina 0:69ac1abc8193 9
shina 0:69ac1abc8193 10 int main(){
shina 0:69ac1abc8193 11 usensor.set_temperature(15);
shina 0:69ac1abc8193 12 while(true){
shina 0:69ac1abc8193 13 usensor.start();
shina 0:69ac1abc8193 14 wait_ms(100);
shina 0:69ac1abc8193 15 dist=usensor.get_dist_cm();
shina 0:69ac1abc8193 16 pc.printf("%dmm\n",dist*10);
shina 0:69ac1abc8193 17 if(dist<100){
shina 0:69ac1abc8193 18 led=1;
shina 0:69ac1abc8193 19 }else{
shina 0:69ac1abc8193 20 led=0;
shina 0:69ac1abc8193 21 }
shina 0:69ac1abc8193 22 }
shina 0:69ac1abc8193 23 }
shina 0:69ac1abc8193 24
shina 0:69ac1abc8193 25