jose ortega cervantes / Mbed 2 deprecated flexometrodigital

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 Serial serialpc( USBTX,USBRX);
00005 TextLCD lcd(D0,D1,D2,D3,D4,D5);
00006 
00007 
00008 
00009 InterruptIn Echo(D8);
00010 DigitalOut Trigg(D9);
00011 Timer timer;
00012 float dist=0;
00013 DigitalOut led(LED2);
00014         void start(){
00015                 timer.reset();
00016                 timer.start();
00017                 }
00018                 
00019       void stop(){
00020           timer.stop();
00021           dist=timer.read_us();
00022           }
00023               
00024     int main(){
00025         Echo.rise(&start);
00026         Echo.fall(&stop);
00027         Trigg=0;        
00028             
00029         while(1){
00030             dist=0;
00031             Trigg=1;
00032             wait_us(10);
00033             Trigg=0;
00034             while(dist==0){
00035                 wait_us(1);
00036                      
00037         }
00038              
00039              dist=dist/58.0;
00040              if(dist>5){
00041                  led=1;
00042                  }else{
00043                      led=0;
00044              }
00045            lcd.locate(0,0);
00046              lcd.printf("la distancia es");
00047              lcd.locate(0,1);
00048              lcd.printf("%f cm",dist);
00049              wait(.3);
00050              
00051              
00052              
00053             
00054          }
00055     }