leuk

Dependencies:   mbed HCSR04

Committer:
harveys
Date:
Tue Apr 09 07:25:01 2019 +0000
Revision:
0:7d87166a1170
Child:
1:a8c5e92c6cbf
ultrasoon test voor driveXchange

Who changed what in which revision?

UserRevisionLine numberNew contents of line
harveys 0:7d87166a1170 1 // Initialize a pins to perform Serial Communication for receive
harveys 0:7d87166a1170 2 // the result of the printf on PC (USB Virtual Com)
harveys 0:7d87166a1170 3 // I suggest to use TeraTerm on PC.
harveys 0:7d87166a1170 4 // TeraTerm configuration must be: 9600-8-N-1 FlowControl None
harveys 0:7d87166a1170 5
harveys 0:7d87166a1170 6 /* EXAMPLE */
harveys 0:7d87166a1170 7 #include "mbed.h"
harveys 0:7d87166a1170 8 #include "hcsr04.h"
harveys 0:7d87166a1170 9
harveys 0:7d87166a1170 10 DigitalIn IR(PA_4);
harveys 0:7d87166a1170 11 DigitalOut led(PA_3);
harveys 0:7d87166a1170 12 Serial pc(USBTX, USBRX);
harveys 0:7d87166a1170 13
harveys 0:7d87166a1170 14 //D12 TRIGGER D11 ECHO
harveys 0:7d87166a1170 15 HCSR04 sensor(D12, D11);
harveys 0:7d87166a1170 16 int main()
harveys 0:7d87166a1170 17 {
harveys 0:7d87166a1170 18 while(1)
harveys 0:7d87166a1170 19 {
harveys 0:7d87166a1170 20 int a = IR;
harveys 0:7d87166a1170 21 if(a==1)
harveys 0:7d87166a1170 22 {
harveys 0:7d87166a1170 23 led=0;
harveys 0:7d87166a1170 24 }
harveys 0:7d87166a1170 25 else
harveys 0:7d87166a1170 26 {
harveys 0:7d87166a1170 27 led=1;
harveys 0:7d87166a1170 28 }
harveys 0:7d87166a1170 29
harveys 0:7d87166a1170 30 long distance = sensor.distance();
harveys 0:7d87166a1170 31 printf("distance %d\r\n",distance);
harveys 0:7d87166a1170 32 wait_ms(50); // 1 sec
harveys 0:7d87166a1170 33
harveys 0:7d87166a1170 34 }
harveys 0:7d87166a1170 35 }