敦哉 品川
/
HC-SR04
超音波センサー
main.cpp
- Committer:
- shina
- Date:
- 2019-12-25
- Revision:
- 0:69ac1abc8193
File content as of revision 0:69ac1abc8193:
#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; } } }