ultrasonido

Dependencies:   mbed mbed-rtos HCSR04

Committer:
Alejandro10
Date:
Thu Nov 19 14:23:27 2020 +0000
Revision:
0:a2d6bebaf8ed
Child:
1:5b7333529d77
ultrasonido

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alejandro10 0:a2d6bebaf8ed 1 #include "mbed.h"
Alejandro10 0:a2d6bebaf8ed 2 #include "HCSR04.h"
Alejandro10 0:a2d6bebaf8ed 3
Alejandro10 0:a2d6bebaf8ed 4 //HCSR04 usensor(PTE1,PTE0);// (trig,echo)
Alejandro10 0:a2d6bebaf8ed 5 HCSR04 usensor(D15,D14);// (trig,echo)
Alejandro10 0:a2d6bebaf8ed 6 Serial pc(USBTX, USBRX); //comunicacion serial
Alejandro10 0:a2d6bebaf8ed 7 // Se encenderan Led's dependiendo de la distancia
Alejandro10 0:a2d6bebaf8ed 8 DigitalOut myled1(LED1);
Alejandro10 0:a2d6bebaf8ed 9 DigitalOut myled2(LED2);
Alejandro10 0:a2d6bebaf8ed 10 DigitalOut myled3(LED3);
Alejandro10 0:a2d6bebaf8ed 11
Alejandro10 0:a2d6bebaf8ed 12 int distancia;//tomara el valor de la distancia
Alejandro10 0:a2d6bebaf8ed 13
Alejandro10 0:a2d6bebaf8ed 14 int main() {
Alejandro10 0:a2d6bebaf8ed 15 pc.baud(9600);
Alejandro10 0:a2d6bebaf8ed 16 while(1) {
Alejandro10 0:a2d6bebaf8ed 17 distancia = usensor.distance(CM);//se toma la distancia en cm y se actua depediendo de esta
Alejandro10 0:a2d6bebaf8ed 18 if(distancia<10){
Alejandro10 0:a2d6bebaf8ed 19
Alejandro10 0:a2d6bebaf8ed 20 myled1=0;
Alejandro10 0:a2d6bebaf8ed 21 myled2=1;
Alejandro10 0:a2d6bebaf8ed 22 myled3=1;
Alejandro10 0:a2d6bebaf8ed 23 }
Alejandro10 0:a2d6bebaf8ed 24 else if(distancia<20){
Alejandro10 0:a2d6bebaf8ed 25
Alejandro10 0:a2d6bebaf8ed 26 myled1=1;
Alejandro10 0:a2d6bebaf8ed 27 myled2=0;
Alejandro10 0:a2d6bebaf8ed 28 myled3=1;
Alejandro10 0:a2d6bebaf8ed 29 }
Alejandro10 0:a2d6bebaf8ed 30 else{
Alejandro10 0:a2d6bebaf8ed 31
Alejandro10 0:a2d6bebaf8ed 32 myled1=1;
Alejandro10 0:a2d6bebaf8ed 33 myled2=1;
Alejandro10 0:a2d6bebaf8ed 34 myled3=0;
Alejandro10 0:a2d6bebaf8ed 35 } pc.printf("distancia es (%d)\n\r",distancia);
Alejandro10 0:a2d6bebaf8ed 36 wait(1);
Alejandro10 0:a2d6bebaf8ed 37 }
Alejandro10 0:a2d6bebaf8ed 38 }
Alejandro10 0:a2d6bebaf8ed 39