Mirte H
/
Lijn_code_af_robotzwenkwiel
leuk
main.cpp
- Committer:
- harveys
- Date:
- 2019-04-09
- Revision:
- 0:7d87166a1170
- Child:
- 1:a8c5e92c6cbf
File content as of revision 0:7d87166a1170:
// Initialize a pins to perform Serial Communication for receive // the result of the printf on PC (USB Virtual Com) // I suggest to use TeraTerm on PC. // TeraTerm configuration must be: 9600-8-N-1 FlowControl None /* EXAMPLE */ #include "mbed.h" #include "hcsr04.h" DigitalIn IR(PA_4); DigitalOut led(PA_3); Serial pc(USBTX, USBRX); //D12 TRIGGER D11 ECHO HCSR04 sensor(D12, D11); int main() { while(1) { int a = IR; if(a==1) { led=0; } else { led=1; } long distance = sensor.distance(); printf("distance %d\r\n",distance); wait_ms(50); // 1 sec } }