Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Ultrasonico_HC-SR04 by
Revision 1:ad8ec262e808, committed 2017-12-20
- Comitter:
- b34196
- Date:
- Wed Dec 20 14:40:23 2017 +0000
- Parent:
- 0:34f7d9ef2f4b
- Commit message:
- english version used to play with kids in Roznov
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 34f7d9ef2f4b -r ad8ec262e808 main.cpp --- a/main.cpp Wed Nov 12 17:53:57 2014 +0000 +++ b/main.cpp Wed Dec 20 14:40:23 2017 +0000 @@ -1,49 +1,49 @@ -/* Programa para utilização do sensor Ultrasom +/* Program for Ultrasonic sensor use */ -/*Interrupções de pinos,só são possíveis nas portas A e D*/ +/*Pin interruptions are only possible with ports A and D*/ #include "mbed.h" - Serial pc(USBTX,USBRX); //Configuração da comunicação serial para enviar o valor do sensor - DigitalOut trig(PTE5,0); //Configuração do pino de Trigger - InterruptIn echo(PTA16); //Configuração da interrupção por pino de Echo + Serial pc(USBTX,USBRX); //Configuration of the serial communication to send the value of the sensor + DigitalOut trig(PTE3,0); //Trigger pin configuration + InterruptIn echo(PTA16); //Echo pin interrupt configuration Timer tempo; float tdist=0, distcm=0, distin=0, dist0=0; - void iniP(){ //Rotina para receber o pulso inicial do pino Echo - tempo.start(); //Rotina para iniciar o contador + void iniP(){ //Routine to receive the initial pulse of the Echo pin + tempo.start(); //Routine to start the counter return; } - void finP(){ //Rotina para pegar o tempo final do pulso + void finP(){ //Routine to get the end time of the pulse - tdist = tempo.read_us(); //Leitura do tempo transcorrido - distcm = tdist/58; //Cálculo da distância detectada em "cm" - distin = tdist/148; //Cálculo da distância detectada em "in" + tdist = tempo.read_us(); //Reading the elapsed time + distcm = tdist/58; // distance "cm" + distin = tdist/148; // distance "in" - tempo.stop(); //Páro o temporizador - tempo.reset(); //Reset para o próximo ciclo + tempo.stop(); //Stop the timer + tempo.reset(); //reset to next cycle return; } int main(){ - + printf("Ultrasonic ranging test \n"); while(1){ - trig=1; //Inicio do trigger - wait_us(10); // 10us de pulso - trig=0; //Fim do trigger + trig=1; //trigger start + wait_us(10); // 10us puls + trig=0; //end of trigger - echo.rise(&iniP); //leitura do inicio do pulso de retorno - echo.fall(&finP); //Leitura do final do pulso de retorno + echo.rise(&iniP); //return pulse start reading + echo.fall(&finP); //Reading the end of the return pulse - if(distcm != dist0){ //rotina para evitar que se envie muitos valores + if(distcm != dist0){ //routine to avoid sending too many values dist0 = distcm; - printf("Distancia detectada pelo sensor %.2f cm \n",distcm); + printf("Distance detected by sensor %.2f cm \r\n",distcm); } - wait_ms(60); //rotina para evitar que o pulso de "trigger" seja confundido com o "echo" + wait_ms(60); //routine to prevent the trigger pulse from being confused with the "echo" }